0

I have a named route. I want to pass two parameters to the 'edit' action (for example {id} and {month}).

I tried to pass parameters through an array, but still not working.

Route::resource('admin/worktimes', 'WorktimesController')->names([
    'index' => 'worktimes',
    'show' => 'worktimes.show',
    'create' => 'worktimes.create',
    'edit' => 'worktimes.edit',
    'store' => 'worktimes.store',
    'update' => 'worktimes.update'
])

{{ route('admin/worktimes', array($id, $month) }}

The url created is 'http://.../admin/worktimes/4/edit?month=2019-05'. I want to have something like 'http://.../admin/worktimes/4/2019-05/edit'.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Asatur
  • 15
  • 1
  • 10
  • Is that the full route definition? Does it contain any more information about the mapped variables? On first sight, you miss the keys in your parameter array – Nico Haase Mar 25 '19 at 10:24

2 Answers2

0

you can't get your desired result with resource

make Route('admin/worktimes/{id}/{month}/edit','WorktimesController@edit') and in your controller edit method will be like public function edit($id,$month){ //your code }

Karan Sadana
  • 1,363
  • 7
  • 11
0

Default resource method is not allowed multiple parameters in edit.

they are autogenerated urls from the resource route.

and if we need to change these then must need to change some core routing function of laravel.

and that will be not a good idea to do. because that affected with all the edit routes of the project.

so we are just overwriting the resource edit route with our route rule.

 Route::get('admin/worktimes/{id}/{month}/edit', ['as' => 'worktimes.edits', 'uses' => 'WorktimesController@edit']);

This rule must be written after the resource route written for a worktimesController in route.php.

Thanks

Yagnik Detroja
  • 921
  • 1
  • 7
  • 22