I have a collection which is generated by $user->roles where role table has role_name and permission columns.
What i want is to convert the $user->roles->permission into an array in jquery so i can use it in select2 components which requires an array.
<script>
$( document ).ready(function() {
$("#role_select").select2();
$('#role_select').val( ).trigger('change');
});
</script>
above code doesnt work and gives the error
Undefined property: Illuminate\Database\Eloquent\Relations\BelongsToMany::$permission
So how can i get an array of permission ?
Note that i have created a pivot table users_roles and also set the relations between the models as belongsToMany
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire