Laravel where and code example
Example 1: laravel orWhere
$camps = $field->camps()->where('status', 0)->where(function ($q) {
$q->where('sex', Auth::user()->sex)->orWhere('sex', 0);
})->get();
Example 2: laravel with and where
$projects = Project::whereHas('projectOffers', function ($offer) {
$offer->where('teacher_id', "Ahmed");
$offer->where('status_id', "Accepted");
})->where('status_id', "inprogress")->get();
Example 3: laravel where
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
Example 4: or where in orm laravel
$a='foo', $b='bar', $c='john', $d='doe';
Coder::where(function ($query) use ($a, $b) {
$query->where('a', '=', $a)
->orWhere('b', '=', $b);
})->where(function ($query) use ($c, $d) {
$query->where('c', '=', $c)
->orWhere('d', '=', $d);
})->get();
Example 5: laravel where
$users = DB::table('users')
->whereDate('created_at', '2016-12-31')
->get();
Example 6: laravel where and where
Table::where('Column', Value)->where('NewColumn', Value)->get();