hermanoloco said:
I'm beginner with laravel.
I have a model "Movie" with several categories like western, suspense, comedy, drama... When I create new comedy, I use the route: Route::get('/movie/comedy', 'MovieController@createMovie');
// route
Route::get('/movie/{category_id}', 'MovieController@create');
// controller
public function create($category_id)
{
$data = [
'categories' => Category::find($category_id)
];
return view('movies.create', $data);
}
the brackets in the route will allow you to pass the value to the controller https://laravel.com/docs/5.3/routing#route-parameters
Thanks w1n78, but I know this solution, my idea is to pass several parameters (minimum 5).
I've found a solution, with Session! I don't know if is the corret but works fine.
Route::get('/movie/western', [ Session::flash('category_id', '2'); Session::flash('title', 'New western'); 'uses' => 'MovieController@createMovie' ]);
public function createMovie() { $actors = Actor::all(); $category_id = Session::get('category_id'); $title = Session::get('title'); return view('movie.create', compact('category_id', 'actors', 'title')); }
Not works fine, because I need to change the value of "Session(title)"
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community