Answers for "laravel where or where"

PHP
6

laravel orWhere

$camps = $field->camps()->where('status', 0)->where(function ($q) {
    $q->where('sex', Auth::user()->sex)->orWhere('sex', 0);
})->get();
Posted by: Guest on October-20-2020
7

laravel not in query

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();
Posted by: Guest on September-26-2020
3

laravel where has

use Illuminate\Database\Eloquent\Builder;

// Retrieve posts with at least one comment containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
})->get();

// Retrieve posts with at least ten comments containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
}, '>=', 10)->get();
Posted by: Guest on May-07-2020
2

wherein laravel

DB::table('user')->whereIn('id', [100,200])->get();
Posted by: Guest on December-16-2020
1

AND-OR-AND + brackets with Eloquent

//mysql query be like this
// ... WHERE (gender = 'Male' and age >= 18) or (gender = 'Female' and age >= 65)

//Eloquent query is
// ...
$q->where(function ($query) {
    $query->where('gender', 'Male')
        ->where('age', '>=', 18);
})->orWhere(function($query) {
    $query->where('gender', 'Female')
        ->where('age', '>=', 65);	
})
//@sujay
Posted by: Guest on October-16-2020
0

where in laravel

$users = Users::whereIn('id', array(1, 2, 3))->get()
Posted by: Guest on July-27-2021

Browse Popular Code Answers by Language