title: laravel model relationships hasOne
body: <p>I have two table, the first is accounts (User model) which is used for auth and the other is students (t_student model) which contains the students details such student id (S_ID)</p>
  
  <p>I am trying to get the S_ID inside the controller in store function for the logged in user.</p>
  
  <pre><code>     $application = new Application;
       $application-&gt;A_ID= $request-&gt; input('A_ID');
       $application-&gt;S_ID= Auth()-&gt;User()-&gt;students()-&gt;S_ID;
       $application-&gt;S_Justification= $request-&gt; input('Justification');
       $application-&gt;save();
       return redirect('/Abstracts')-&gt;with ('success', 'application submitted' );
  </code></pre>
  
  <p>MY User model (accounts table)</p>
  
  <pre><code>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 -&gt;hasMany('App\Project' , 'PI_ID');
  }
  public function academics(){
      return $this -&gt;hasOne('App\T_user', 'Account_ID');
  }
  public function students(){
      return $this -&gt;hasOne('App\t_student', 'Account_ID');
  }}
  </code></pre>
  
  <p>my t_student model</p>
  
  <pre><code>class t_student extends Model{
  protected $table = 't_student';
  protected $primaryKey = 'S_ID';
  
  public function account(){
  return $this -&gt;belongsTo('App\User', 'Account_ID');}
  </code></pre>
  
  <p>and I am getting this error</p>
  
  <pre><code>Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$S_ID
  </code></pre>
  
  <p>EDIT: The error I am getting is related to my controller </p>
  
  <pre><code>         $application-&gt;S_ID= Auth()-&gt;User()-&gt;students()-&gt;S_ID;
  </code></pre>
  
  <p>and the reason is my relationship but I am not sure what is wrong about it </p>