xxxxxxxxxx
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere(function($query) {
$query->where('name', 'Abigail')
->where('votes', '>', 50);
})
->get();
xxxxxxxxxx
$results = DB::table('orders')
->where('branch_id', Auth::user()->branch_id)
->when($request->customer_id, function($query) use ($request){
return $query->where('customer_id', $request->customer_id);
})
->get();
xxxxxxxxxx
This:
Model::where()->get();
Is the same as:
Model::query()->where()->get();
Model::query() used to instantiate a query and then build up conditions based on request variables.
$query = Model::query();
if ($request->color) {
$query->where('color', $request->color);
}
xxxxxxxxxx
DB::table('users')->insert([
'email' => 'kayla@example.com',
'votes' => 5
]);
xxxxxxxxxx
<?php
Route::get('games', function () {
$games = DB::table('games')->get();
return view('games', ['games' => $games]);
});
xxxxxxxxxx
$freePages = Page::where(function ($query) {
$query->where('menu_id', '<>', $this->menu->id);
$query->orWhereNull('menu_id');
})->where('status', '=', true)
->get();
xxxxxxxxxx
DB::table('users')->insert([
'email' => 'kayla@example.com',
'votes' => 0
]);