Build query on Laravel

-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 the weekday and id parameters do not exist I want to update the table where the id_restaurant is equal to 303 how to construct this query in Laravel?     

asked by anonymous 01.10.2018 / 15:43

1 answer

1

You can do a simple check in 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 you read the documentation to better understand Query   Builder of laravel

    
01.10.2018 / 16:53