samedi 18 juin 2016

Auth::user() with a relationship?

I have a regular users table, but I also have a user_settings table with the following relationship in my UserSettings.php file:

public function user()
{
    return $this->belongsTo('App\Models\User');
}

I want to be able to access the user and their settings by doing Auth::user(), but doing Auth::user()->settings->column_name gives me an error:

Trying to get property of non-object

How can I get the user's settings using Auth::user()?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire