We have two model class, one is User the other one is Division, user belongs to one division and division has many users. Users table only has one column named division_id, the other division information like “division name” we can get from Divisions table.
useIlluminate\Contracts\Auth\MustVerifyEmail; useIlluminate\Database\Eloquent\Factories\HasFactory; useIlluminate\Foundation\Auth\UserasAuthenticatable; useIlluminate\Notifications\Notifiable; useLaravel\Sanctum\HasApiTokens; useIlluminate\Database\Eloquent\Model; //by default this line is not here, you need to add it manually
Instead you should use user->division->name to get the name of the division, but if you directly use the property name name it will throw an other error, beacuse the default Laravel user model do not import Eloquent Model.
1
Attempt to read property "name" on null
To solve this problem we need to add a this line to your User model file.