I am using Laratrust with laravel to display records from the database according to roles. Every record has a role type field (example to table below).
In my blade view, I want to display them as the code (the variable is called $types
).
<select name="type" id="" class="form-control">
@foreach ($types as $type)
@role($type->role)
<option value="{{ $type->id }}">
{{ $type->name }} {{ $type->role }}
</option>
@endrole
@endforeach
</select>
It shows nothing. My data is correct. I tried to write the roles type by hand, and it worked. If I left the @role()
empty, it shows an error, so it is not a problem of the role interpreted before the variable is passed. Any help would be appreciated.
2
Answers
the variable type was String and @role only worked with arrays so I add an accessor in the model to decode the data before getting it.
You can try this