[英]Is it possible to return a view (using blade) with two variables in laravel?
I have to do one of these pages with a form that will search for a meal and its recipe according to a dishtype or cuisine type etc... Here is my function to return the view but there is an error in the line that i show in bold below:我必须使用一个表格来执行这些页面之一,该表格将根据菜肴类型或菜肴类型等搜索餐点及其食谱......这是我的 function 以返回视图,但我显示的行中有错误下面用粗体表示:
public static function SearchPage()
{
$DishType = DishType::getAllDishType();
$CuisineType = CuisineType::getAllCuisineType()
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
CuisineType::getAllCuisineType()
]);
}
And Here is a part of a view where i would like to use a variable:这是我想使用变量的视图的一部分:
<label for="DishType">Dish type :</label>
<select id="DishType" name ="DishType">
@foreach($DishType as $Dish)
<option value="Dessert">{{$Dish->dish}}</option>
@endforeach
</select>
and i'd like to do the same with the cuisine type but can't because I don't know how to return multiple variables..我想对美食类型做同样的事情,但不能因为我不知道如何返回多个变量..
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
'CuisineType' => CuisineType::getAllCuisineType()
]);
Then you have access in your blade file with the array keys: DishType
and CuisineType
.然后,您可以使用数组键访问刀片文件:
DishType
和CuisineType
。
Obviously possible to send two variables from controller to blade.显然可以将两个变量从 controller 发送到刀片。
$dishType' = DishType::getAllDishType();
$cuisineType = CuisineType::getAllCuisineType();
return \view("vueRecipeSearch", compact('dishType', 'cuisineType'));
And on the blade file, you have to access these two variables like by $dishType
and $cuisineType
.在刀片文件上,您必须通过
$dishType
和$cuisineType
访问这两个变量。
return view ('vueRecipeSearch',compact('dishType', 'cuisineType'));返回视图 ('vueRecipeSearch',compact('dishType', 'cuisineType')); No Need Add Forward Slash or Backward Slash.
无需添加正斜杠或反斜杠。 Simple
简单的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.