Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

with relation laravel

//Single relationship
$billings = Billing::with('user')->get();
// sinlge with selected colums
$billings = Billing::with('user:id,name')->get();

// multiple relations
$billings = Biling::with(['user', 'subscription'])->get();

// nested relations
$schools = School::with('class.user')->get();

// Constraining Eager Loads
$users = User::with(['posts' => function ($query) {
    $query->where('title', 'like', '%code%');
}])->get();
$users = User::with(['posts' => function ($query) {
    $query->orderBy('created_at', 'desc');
}])->get();
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #relation #laravel
ADD COMMENT
Topic
Name
7+9 =