I have a problem with optional parameters that gives 404 error in laravel 7

341 Views Asked by At

I have the following function in laravel 7:

public function create(Franchise $franchise = null)
{
  ...
}

And the route is as follows:

Route::get('series/create/{franchise?}', 'SerieController@create')->name('serie.create');

when I execute it with parameters for example page_name/series/create/1 it executes normally but when I execute without parameters page_name/series/create I get an error 404 | Not Found.

I also used dd() at the beginning of the function and it keeps giving me the same error

I also did the same with index:

Route::get('series/{franchise?}', 'SerieController@index')->name('serie');

And there it executes me well with or without parameters Is there a route problem?

1

There are 1 best solutions below

0
On

it seems you didn't add /series/create to your router. This is the reason why Laravel doesn't see this route and throws a 404 error. Add that route to your router file: