У меня есть две таблицы: первая - это учетные записи (модель пользователя), которая используется для аутентификации, а другая - студенты (модель t_student), которая содержит сведения о студентах, такие как идентификатор студента (S_ID)
Я пытаюсьчтобы получить S_ID внутри функции контроллера в хранилище для вошедшего в систему пользователя.
$application = new Application;
$application->A_ID= $request-> input('A_ID');
$application->S_ID= Auth()->User()->students()->S_ID;
$application->S_Justification= $request-> input('Justification');
$application->save();
return redirect('/Abstracts')->with ('success', 'application submitted' );
MY Модель пользователя (таблица счетов)
class User extends Authenticatable{
protected $table = 'accounts';
protected $primaryKey = 'Account_ID';
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password', 'Account_Type', 'name'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function abstracts(){
return $this ->hasMany('App\Project' , 'PI_ID');
}
public function academics(){
return $this ->hasOne('App\T_user', 'Account_ID');
}
public function students(){
return $this ->hasOne('App\t_student', 'Account_ID');
}}
my t_student model
class t_student extends Model{
protected $table = 't_student';
protected $primaryKey = 'S_ID';
public function account(){
return $this ->belongsTo('App\User', 'Account_ID');}
и я получаю эту ошибку
Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$S_ID
РЕДАКТИРОВАТЬ: ошибка, которую я получаю, связана с моим контроллером
$application->S_ID= Auth()->User()->students()->S_ID;
и причина в моих отношениях, но я не уверенчто в этом плохого