How Can I return two variables from same method/function to one view in laravel 5.4?

Danish Tahir

I'm a beginner with Laravel 5.4 but I'm stuck at some point. Please tell me how can I return two variables from one function / method to the same view. I've googled but all the contents are so old!!!

Here is my controller

public function index(Request $fetch){
      $category = Category::all();
      $fetch_cat = Category::find($fetch)->first();
      //$data = array('category' => $category, 'fetch_cat'=> $fetch_cat);
      return view('admin/create-menu', compact('data'));
}

I know I need to edit only this function and then in view I'll handle them.

Kris Roofe

You can do it like this:

$data = array('category' => $category, 'fetch_cat'=> $fetch_cat);
return view('admin/create-menu', $data);

or

return view('admin/create-menu', compact('category', 'fetch_cat'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I force two instance variables to be of the same generic type?

How can I send two different text intents to the same textview from one activity to another?

In Laravel, how can i return a specific *column* from a *table* inside my API Controller ? I'm using Laravel 5

How to return all content from three variables in one function in Laravel?

How can I use my custom class in a view on Laravel 5

How can I add two variables on one line in HAML?

How to return two views from One Function in Laravel 5.2

How can i include this menu to all my view ? [Laravel 5]

Laravel 5 - How can I pass html data to view

How can I pass two variables to a view?

How can I have two alerts on one view in SwiftUI?

How can i retrieve or return different records on the same view in Laravel?

Return logic from Controller into View Laravel 5

How can I return two different values from the same column in a SQL Join?

How can I save two models at the same time in Laravel?

How can I split one string into two variables in TypeScript?

How can I compare same type of variables in one condition?

How can I display data from multiple entities in same view and group them by one of the entity

How can I return from a C# 8 switch expression into a property and two locally declared variables?

How can I make two() to ignore the same cases as one()?

How can I return True if same character is found in two lists?

How can I have two for loops in the same list but the second one to start from the next value of the first loop?

How do I return a POST request and a view in the same controller, in Laravel?

How can I return two variables from a function on python 3?

How do I check if two input variables are in the same position in two different lists and return as valid?

How can I render two variables in src attribute of razor view?

How can I return view and pass in data in Laravel with Ajax?

How can I return Laravel controller to multiple view files?

How can I plot two linear regressions on one same graph?