I have my Auth session, which returns the user's data:
print_r(Auth::user());
In this session, I want to add the company data associated with the user. In my User model, I added the following:
public function empresa()
{
$this->belongsTo(Ewempresa::class,'empresa_id');
}
To get company data, in this case the field " morada_fiscal
", I have this:
echo Auth::user()->empresa->morada_fiscal;
What happens is that the company is not placed in the Auth session.
My model User:
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
public function siteuserlangs()
{
return $this->hasMany('Siteuserlang');
}
public function siteusertags()
{
return $this->hasMany('Siteusertag');
}
public function validate($input)
{
$rules=array(
'uniqueid' => 'required',
//'username' => 'required|email',
'active' => 'numeric',
'password' => 'required|min:6',
'email' => 'required|email',
//'locale' => 'required',
//'name' => 'required|min:6',
);
return Validator::make($input,$rules);
}
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'siteusers';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
public function empresa()
{
return $this->belongsTo(Ewempresa::class,'empresa_id');
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
}
?>