[英]Is it possible to return a view (using blade) with two variables in laravel?
我必须使用一个表格来执行这些页面之一,该表格将根据菜肴类型或菜肴类型等搜索餐点及其食谱......这是我的 function 以返回视图,但我显示的行中有错误下面用粗体表示:
public static function SearchPage()
{
$DishType = DishType::getAllDishType();
$CuisineType = CuisineType::getAllCuisineType()
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
CuisineType::getAllCuisineType()
]);
}
这是我想使用变量的视图的一部分:
<label for="DishType">Dish type :</label>
<select id="DishType" name ="DishType">
@foreach($DishType as $Dish)
<option value="Dessert">{{$Dish->dish}}</option>
@endforeach
</select>
我想对美食类型做同样的事情,但不能因为我不知道如何返回多个变量..
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
'CuisineType' => CuisineType::getAllCuisineType()
]);
然后,您可以使用数组键访问刀片文件: DishType
和CuisineType
。
显然可以将两个变量从 controller 发送到刀片。
$dishType' = DishType::getAllDishType();
$cuisineType = CuisineType::getAllCuisineType();
return \view("vueRecipeSearch", compact('dishType', 'cuisineType'));
在刀片文件上,您必须通过$dishType
和$cuisineType
访问这两个变量。
返回视图 ('vueRecipeSearch',compact('dishType', 'cuisineType')); 无需添加正斜杠或反斜杠。 简单的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.