I have a User
and a Profile
class in my application with 1:1 relationship.
Inside my ProfileController@show
I can instantiate and build query perfectly fine for each of them but these two lines :
$userProfile=$profile->with('user')->where('id',1)->firstOrFail();
$userProfile=$user->with('profile')->where('id',3)->firstOrFail();
The first one sends a fatal error Exception with the message: "Class User Not Found" and the message for the second one is "Class Profile Not Found"
I also tried facades and different way of building query but it didn't work.
According to this question I think there is something wrong with my relationship. I passes the foreign_key explicitly, but it doesn't work.
Here is some details:
User class:
class User extends \Eloquent implements UserInterface, RemindableInterface
{
public function profile()
{
return $this->hasOne('Profile', 'id');
}
}
Profile class
class Profile extends \Eloquent
{
public function user()
{
return $this->belongsTo('User', 'id');
}
}
Database schema: table "users"
id
password
email
username
table "profiles"
id
user_id
about
Thanks in advanced.