I have a controller that has 3 tables of data that I want to pass to a view page but view() only accepts 2 variables
public function createShowTime(){
$eventdays = Eventday::all();
$movies = Movie::all();
$showtimes = Showtime::all();
return view('admin.layouts.createshowtime', ["eventdays" => $eventdays], ["movies" => $movies], ["showtimes" => $showtimes]);
}
the problem here is that view() doesn't accept the third variable which is ["showtimes" => $showtimes] so how can I pass it?
CodePudding user response:
Don't send it as separate arrays, you can send it as a single associative arrays like this:
public function createShowTime(){
$eventdays = Eventday::all();
$movies = Movie::all();
$showtimes = Showtime::all();
return view('admin.layouts.createshowtime', ["eventdays" => $eventdays, "movies" => $movies, "showtimes" => $showtimes]);
}
Read more about Passing Data To Views
CodePudding user response:
do this
public function createShowTime(){
$eventdays = Eventday::all();
$movies = Movie::all();
$showtimes = Showtime::all();
return view('admin.layouts.createshowtime')->with('eventdays',$eventdays)->with('movies',$movies)->with('showtimes',$showtimes);
}
you can also do this with another way
public function createShowTime(){
$eventdays = Eventday::all();
$movies = Movie::all();
$showtimes = Showtime::all();
return view('admin.layouts.createshowtime',compact('eventdays','movies','showtimes'));