mardi 2 janvier 2018

How to put array data from laravel to jquery array?

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



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2q8vKcs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire