Hi, I have two tables, table User and table Accounts (User hasMany Accounts). After login, i need to push the related accounts to the Auth session or to another session.
Where I have to put my code? and how to do that?
It sounds like you want to always load the Accounts relationship (assuming you have a relationship defined)?
If so, in your user model, you can just add the public $with = ['accounts'];
And then any time the user is loaded, so will their accounts, which would be accessed via Auth::user()->accounts; (or anywhere else that has the user object)
class User extends Authenticatable
{
//whenever user is retrieved, load their accounts
public $with = ['accounts'];
public function accounts()
{
return $this->hasMany('App\Accounts');
}
}