Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

eager loading in hasmany belongsto relationship

class Post extends Model
{
   //in case of belongs to relationship we need to specify foreign key
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #eager #loading #hasmany #belongsto #relationship
ADD COMMENT
Topic
Name
7+4 =