return 视图(使用 blade)是否可以在 laravel 中使用两个变量?
Is it possible to return a view (using blade) with two variables in laravel?
我必须使用一个表格来完成其中一个页面,该表格将根据菜肴类型或菜肴类型等搜索餐点及其食谱...
这是我 return 视图的函数,但是我在下面以粗体显示的行中有一个错误:
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 多个变量..
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
'CuisineType' => CuisineType::getAllCuisineType()
]);
然后您可以使用数组键访问 blade 文件:DishType
和 CuisineType
。
显然可以将两个变量从控制器发送到 blade。
$dishType' = DishType::getAllDishType();
$cuisineType = CuisineType::getAllCuisineType();
return \view("vueRecipeSearch", compact('dishType', 'cuisineType'));
并且在 blade 文件中,您必须通过 $dishType
和 $cuisineType
访问这两个变量。
return 视图 ('vueRecipeSearch',compact('dishType', 'cuisineType'));
无需添加正斜杠或反斜杠。简单
我必须使用一个表格来完成其中一个页面,该表格将根据菜肴类型或菜肴类型等搜索餐点及其食谱... 这是我 return 视图的函数,但是我在下面以粗体显示的行中有一个错误:
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 多个变量..
return view("vueRecipeSearch", [
'DishType' => DishType::getAllDishType(),
'CuisineType' => CuisineType::getAllCuisineType()
]);
然后您可以使用数组键访问 blade 文件:DishType
和 CuisineType
。
显然可以将两个变量从控制器发送到 blade。
$dishType' = DishType::getAllDishType();
$cuisineType = CuisineType::getAllCuisineType();
return \view("vueRecipeSearch", compact('dishType', 'cuisineType'));
并且在 blade 文件中,您必须通过 $dishType
和 $cuisineType
访问这两个变量。
return 视图 ('vueRecipeSearch',compact('dishType', 'cuisineType')); 无需添加正斜杠或反斜杠。简单