Laravel 4 One To Many relationship Error -
i laravel newbie , trying follow documentation.so have 2 models, 'user' model , 'userphone' model. user has many phones.
user model:
public function userphone() { return $this->hasmany('userphone'); }
userphone model:
public function user(){ return $this->belongsto('user'); }
on controller trying "copy" documentation:
$userphone = user::find(1)->userphone;
well result error:
trying property of non-object
i know missing here , cannot find it.
i'm pretty sure don't have user id of 1.
$userphone = user::find(1)->userphone;
this should work, but, if doesn't find user first part:
user::find(1)
i return null , null not object, error: trying property of non-object
.
my advice is, try this
var_dump( user::find(1) );
and if receive null, found problem.
Comments
Post a Comment