Home > front end >  Is it possible to return a view (using blade) with two variables in laravel?
Is it possible to return a view (using blade) with two variables in laravel?

Time:01-03

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 :

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..

CodePudding user response:

return view("vueRecipeSearch", [
        'DishType' => DishType::getAllDishType(),
        'CuisineType' => CuisineType::getAllCuisineType()
    ]);

Then you have access in your blade file with the array keys: DishType and CuisineType.

  • Related