Support the ongoing development of Laravel.io →
Requests Views Forms
Last updated 1 year ago.
0

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

0

Thanks w1n78, but I know this solution, my idea is to pass several parameters (minimum 5).

0

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)"

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.