I'm a beginner in Laravel, can you help me please ?
When the user is authentifate, I want to show his name in nav bar.
The problem is that I have 2 table (members and students), the name (first_name) is store in students table et the authentification proceed with members table.
So when I call, in blade, Auth()->user()->name or Auth()->user()->first_name, it's doesn't work..
Then you can create a Student model if you don't already have one and in your User model you can add the following relation
public function student()
{
return $this->belongsTo('App\Student');
}
And then if I understand correctly, your current User model uses the members table, so you can do :
auth()->user()->student->first_name
If you're not sure that the user will be authenticated or if the user (member) might not have a related student, you should use null coalescing to avoid an error.
auth()->user()->student->first_name ?? '' // Here the empty string is the default value if the user or the student isn't set.