Search code examples
laravellaravel-bladelaratrust

Passing role type to Laratrust form database variable


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).

enter image description here

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.


Solution

  • 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.