Good morning Try to insert in my database via tinker, so I have 2 table, "Autor" has one "Profile", so like you see in my Shell, When I call this line: " Author::profile()" give me this error
CodePudding user response:
The first line you should enter the correct namespace as you share the image the folder you stored all models in is called models
in author model
public function profile()
{
return $this->hasOne('App\Models\Pofile');
}
in profile model
public function author()
{
return $this->belongsTo('App\Models\Author');
}
Second, you can't call any relations method statically from the model if you want to use it you should use eager loading
Author::with('profile')->first();
CodePudding user response:
thank you friend, I need to verify my name space return $this->hasOne('App\Models\Profile');