laravel query 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 sql query
use Illuminate\Support\Facades\DB;
$users = DB::select('select * from users');
foreach ($users as $user) {
echo $user->name;
}
Example 3: laravel db query
$users = DB::table('users')
->where('votes', '>', 100)
->orWhere(function($query) {
$query->where('name', 'Abigail')
->where('votes', '>', 50);
})
->get();
Example 4: Laravel query where and
Table::where('Column', Value)->where('NewColumn', Value)->get();
Example 5: laravel db inserr
DB::table('users')->insert([
['email' => '[email protected]', 'votes' => 0],
['email' => '[email protected]', 'votes' => 0],
]);
Example 6: query builder laravel
use Illuminate\Database\Eloquent\Builder;
public function scopeFakePersons(Builder $query): Builder
{
return $query->where('is_fake', 1);
}