I had searched for how to add parameters to resource route
Route::resource('posts','PostsController');
// became
Route::resource('posts/category.post','PostsController');
now , by the category.post I can declare additional parameters to all resource routes
but they are required , my question is how to make them optional ?
I tried something like this
Route::resource('posts/category?.post','PostsController');
to make the category parameter be an optional one , but that didn't work with me .
how I can do so ?
thank you .
You can try this, not sure though..
Route::resource('posts', 'PostsController')->except(['store' ]);
Route::post('posts/category', 'PostsController@store');
Resource route is not just a "route"
You may see it as a route group, but it is predefined and can easily be implemented when you have a normal resource controller
If you want to change the parameters you'll have to define the routes individually
Then you can make the parameters optional as needed
Route::post('/posts/category/{post?}, 'PostsController@store');
See the following docs
https://laravel.com/docs/7.x/routing#parameters-optional-parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With