laravel when

169

laravel db inserr -

DB::table('users')->insert([
    'email' => '[email protected]',
    'votes' => 0
]);

laravel update from query -

$affected = DB::table('users')
              ->where('id', 1)
              ->update(['votes' => 1]);

laravel when -

/* you may only want to apply a where statement if a given input value
is present on the incoming request.
*/
$role = $request->input('role');

$users = DB::table('users')
                ->when($role, function ($query, $role) {
                    return $query->where('role_id', $role);
                })
                ->get();

Comments

Submit
0 Comments