Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

eager load relationships by default in the model laravel

class Post extends Model
{
    protected $with = ['category', 'author'];

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function author()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #eager #load #relationships #default #model #laravel
ADD COMMENT
Topic
Name
3+5 =