Do your condition checking first, that will make your code clear and readable
like @RJParikh
$drinks = 0;
if(beverage == 1)
$drinks = 1;
else if(beverage == 2)
$drinks = 2;
Or if you have limited number of entry do like @Zayn Ali
$drinks = [ 1 => 1, 2 => 2 ]; // $beverageValue => $drinksValue
Then use insert -
DB::table('food')->insert([
......,
......,
]);
But keep in mind if you use insert like this you have to make the fields fillable from model. Better you make a model on food table and follow @Firas Rassas answer. Combining answers your code will look like below -
$drinks = 0;
if(beverage == 1)
$drinks = 1;
else if(beverage == 2)
$drinks = 2;
$food = new Food(); // new instance of food model
$food->dessert = $dessert1;
$food->drinks = $drinks;
$food->save();
drinks=$beverage