簡體   English   中英

是否可以在 laravel 中返回具有兩個變量的視圖(使用刀片)?

[英]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()
    ]);

然后,您可以使用數組鍵訪問刀片文件: DishTypeCuisineType

顯然可以將兩個變量從 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM