Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading