2

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.

LF00
  • 27,015
  • 29
  • 156
  • 295
Danish Tahir
  • 107
  • 11

1 Answers1

3

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'));
LF00
  • 27,015
  • 29
  • 156
  • 295