Laravel 4 Route :: resource with several parameters

I am trying to create a REST project, but I have a problem. I have a resource schedule. Therefore, the normal notation is /schedules/{id}not very applicable, since I would like to have /schedules/{day}/{month}/{year}, and then apply REST and have /edit, etc.

Is there any way to do this using Route::resource()? or do i need to make them through Route::get()?

+3
source share
3 answers

As far as I know, route :: resource gives you routes that are described in detail in the documentation , so why you need to declare your own route. He still remains calm, and if this is only one of the resourceful routes that you want to change, you can still do the following, because the routes are prioritized in the order in which they are announced.

Route::get('schedule/{day}/{month}/{year}/edit', array('as' => 'editSchedule', 'uses' => 'ScheduleController@edit'));
Route::resource('schedule', 'ScheduleController');
+4
source

Yes, there is a very simple way. Here is an example:

Indicate your route as follows:

Route::resource("schedules/day.month.year", "ScheduleController");

The request will look like this:

/schedules/day/1/month/12/year/2014

And now you can get all three parameters in the show method of your controller or:

public function show($day, $month, $year)
+1
source

, , . . laravel 5.1

laravel: http://laravel.com/docs/5.1/routing#named-routes

Route::get('user/{id}/profile', ['as' => 'profile', function ($id) {
    //
}]);

$url = route('profile', ['id' => 1]);

Route: resource.

:

Route::resource('{foo}/{bar}/dashboard', 'YourController');

Will create named routes, for example: {foo}.{bar}.dashboard.show

To call this using the route method, you configure it as follows.

route('{foo}.{bar}.dashboard.show', ['foo' => 1, 'bar'=> 2])

What will url create yourdomain.com/1/2/dashboard

Hope this is helpful.

Pascal

+1
source

All Articles