0
Guys, I’m with 2 related tables and I want to show you 1 dice that has a just "pulling" this relationship.
tables:
Users:
Permissions:
Table that will list:
Code:
@foreach(App\User::all() as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->permission->name}}</td>
<td>{{$user->email}}</td>
</tr>
@endforeach
Model "User":
public function permission()
{
return $this->hasOne('App\Permission', 'id', 'role');
}
error:
What is the foreign permission key? id or name?
– adventistaam
id is the permission key, but I want to show the name
– Victor Gabriel
The name is of the user?
– adventistaam
name is of the permission I want it to appear, but also name in User
– Victor Gabriel
You can see in the annex I put to the question
– Victor Gabriel
Try to put it like this:
{{ $user->permission->name }}
– adventistaam
error, I will put in the publication
– Victor Gabriel
The two users have scrolls registered for it? you can try to encompass in an optional method, for example
{{ optional($user->permission)->name }}
if the user has no relation to permission, will return empty– arllondias
yes, each has its own registered role
– Victor Gabriel
Var_dump user output
– adventistaam
Try it this way
{{ $user->permission[0]->name }
– adventistaam
It doesn’t do that up, it’s gambiarra. I’m sorry, but it is. It has the right.
– Diego Souza
As it is in the controller?
– adventistaam
it was no way
– Victor Gabriel
controller does not have any function
– Victor Gabriel