0

I have a problem with my routes in Laravel 7 not sure where I a, going wrong here.

I have this route declaration:

Route::group(['prefix'=>'config', 'namespace'=>'Config'], static function () {
    Route::resource('id-generation', 'IDSettingsController',  ['names'=>'config.id_generation'])->only(['index', 'edit', 'update']);
   
});

Then a controller:

public function edit(IdSetting $setting)
    {
        return view('config.id.edit')->with(['setting'=>$setting]);
    }

Then a view:

<form method="post" action="{{route('config.id_generation.update', ['id_generation'=>$setting])}}">
                @method('patch')
                @csrf

                <x-inputs.text-input name="prefix" :model-object="$setting" />
                <x-inputs.button/>

            </form>

But I keep getting errors:

Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameters for [Route: config.id_generation.update] [URI: config/id-generation/{id_generation}].(View: F:\PROJECTS\PHP\app\resources\views\config\id\edit.blade.php)

In as much as I can see, I have done everything correctly. Even artisan command route:list can clearly show the route with its parameters etc.

Where might I be getting it wrong.

Surprisingly if i change it to {{url('config/id-generation/', $setting)}} everthing seeems to be working fine.

FreddCha
  • 465
  • 2
  • 8
  • 15
  • because `$setting` is an empty new instance of a model ... for implicit model binding to take place you need to match the route parameter name with the name of the parameter of the method ... so `setting != id_generation` https://laravel.com/docs/7.x/routing#implicit-binding – lagbox Sep 07 '20 at 11:32
  • 1
    You are a star!! – FreddCha Sep 07 '20 at 11:37

1 Answers1

1

you have to match your model variable name to your ressource name, you can customize it with as:

Route::group(['prefix'=>'config', 'namespace'=>'Config'], static function () {
    Route::resource('id-generation', 'IDSettingsController',  ['names'=>'config.id_generation', 'as' => 'setting'])->only(['index', 'edit', 'update']);
   
});
Mathieu Ferre
  • 4,246
  • 1
  • 14
  • 31