mardi 1 novembre 2016

Laravel 5.3 Join table to Auth user class

i'm working on a CRM that should work with multi languages

my users table looks like this:

Users

id
first_name
last_name
email
password
**language_id**

Languages

id
name
short_name //en,fr,ru etc

i'm trying to get the user's language short name when the user is login i tried this:

Auth::user()->language()->short_name; and also this Auth::user()->language->short_name;

and it's not working, i add this to the User model:

public function language()
{
        return $this->belongsTo('App\Language');
}

and this part to the Language model:

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

what am i doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire