labib47
222
6
Laravel

Eloquent ORM return null

Posted 5 months ago by labib47

Hi , Im just trying to create a simple one to one relationship between User and Company Profile . However it always return null even the data is available in the table .

This is for my company profile class :-

protected $table = "company_profile";

protected $guarded = ["id","company_name","contact_person_name","email"];

public function user()
{
    return $this->belongsTo('App\User','user_id','id');
}

This is for my user class :-

protected $table = "users_employer";
/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'company_name','contact_person_name','email', 'password',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

public function company()
{
   return $this->hasOne('App\CompanyProfile','user_id','id');
}

If I'm using normal join using query it can be done . Somehow using orm this can't be done .

Please sign in or create an account to participate in this conversation.