Build query in Laravel

Asked

Viewed 58 times

-3

    `update `table` set is_available = 0 where id_restaurant = 303 (and weekday = ? or id = ? )`

    $weekday = $request->input('weekday', '');
    $table = $request->input("id", ''); 


//Query em construção        
    DB::table('table')
      ->where('id_restaurant', $this->restaurantId)
      ->update(['is_available' => 0]);

parameters between parentheses are optional, when weekday and id parameters do not exist I want to update the Where table id_restaurant equals 303 how to build this query in Laravel ?

1 answer

1


You can do a simple check on the request to know the value being returned


if(($request->input('weekday') == '') && ($request->input('id') == '')) {
  //Se for vazio seta para 303
      DB::table('table')
      ->where('id_restaurant', '303')
      ->update(['is_available' => 0]);
}

I recommend reading the documentation to better understand the Query Builder of the Laravel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.