xxxxxxxxxx
//No translations
$banners = Banner::where(function ($query) {
$query->where('title', 'like', '%'.$this->search.'%')
->orWhere('description', 'like', '%'.$this->search.'%');
})
->where('type_id', $this->type->id)
->orderBy($this->sort, $this->direction)
->paginate($this->cant);
//with translations
$banners = Banner::whereNull('deleted_at')->withTranslation()
->where(function ($query) {
$query->where('type_id', $this->type->id)
->orWhereTranslationLike('title', '%'.$this->search.'%')
->where('type_id', $this->type->id)
->orWhereTranslationLike('description', '%'.$this->search.'%')
->where('type_id', $this->type->id);
})
->orderBy($this->sort, $this->direction)
->paginate($this->cant);
xxxxxxxxxx
Model::where(function ($query) {
$query->where('a', '=', 1)
->orWhere('b', '=', 1);
})->where(function ($query) {
$query->where('c', '=', 1)
->orWhere('d', '=', 1);
});
xxxxxxxxxx
// Retrieve a model by its primary key...
$flight = App\Models\Flight::find(1);
// Retrieve the first model matching the query constraints...
$flight = App\Models\Flight::where('active', 1)->first();
// Shorthand for retrieving the first model matching the query constraints...
$flight = App\Models\Flight::firstWhere('active', 1);
xxxxxxxxxx
return Destination::orderByDesc(
Flight::select('arrived_at')
->whereColumn('destination_id', 'destinations.id')
->orderBy('arrived_at', 'desc')
->limit(1)
)->get();
xxxxxxxxxx
php artisan make:model Flight --migration
php artisan make:model Flight -m
xxxxxxxxxx
Visitor::select('country')
->withCount('id')
->groupBy('country')
->latest()
->get()
//or
Visitor::query()->groupBy('country')->orderByDesc('count')->select('country' ,DB::raw('COUNT(1) as count'))->get()
xxxxxxxxxx
$model = App\Models\Flight::where('legs', '>', 100)->firstOr(function () {
// ...
});
xxxxxxxxxx
<?php
$flights = App\Models\Flight::all();
foreach ($flights as $flight) {
echo $flight->name;
}