laravel - Entrust not finding user's roles -
I have the following in my controlling method that gives JSON on my view:
Public Function RolesForUser () {$ userid = input :: get ('userid'); $ Assigned = DB :: table ('assigned_roles') - & gt; Select (Arrays ('role_id')) - & gt; Where ('user_id', '=', $ userid) - & gt; get (); $ User = user :: find ($ userid); $ Roles = $ user- & gt; Roles (); $ Data = array ('assigned' = & gt; $ assigned, 'roles' = & gt; $ roles); Return Feedback: Jason ($ data); }
The following (inspected using Fiddler):
{"Assigned": [{"role_id": "2" }, "Role_id" "3"}, {"role_id": "4"}], "roles": {}}
SQL statements using query builder correct results , But the method that uses anestust (copying since making a change to my user model) does not return any role.
I also tried to solve, but it only returns a SQL error.
My User Model:
Extends the user's user-friendly user interface, use the reminder interface {HasRole; / ** * Database table used by model * * @ string * / protected $ table = 'user'; / ** * Attributes excluded from the JSON form of the model * * @ sir array * / hidden $ hidden = array ('password'); Protected $ primaryKey = 'UserID'; Public $ timestamp = false; / * Standard methods for summarizing * / Public function roles () {Return $ this- & gt; Has many ('role'); }}
It looks like you have a roles
The method should not be defined that the use of HasRole
connects to the roles
model with the user
model.
Take a look at the other things that add HasRole
to your model:
Roles () gives returns to a relationship - & Gt; Roles
or - & gt; Roles () - & gt; Received ()
.
It has been recommended to go back
Hope it helps.
Comments
Post a Comment