How to pass default parameters to laravel controller in a get route
Ad
I have a route like that:
Route::get('category/{id}/{date?}', array('as' => 'category/date', 'uses' => '[email protected]etCategory'));
I want to run @getCategory with default parameters when called '/' root route. So if '/' route called, getCategory function should run with id=1 and date=2015-12-18.
How should I do that?
Ad
Answer
Ad
Register it as a separate route:
Route::get('/', '[email protected]')->named('home');
Route::get('category/{id}/{date?}', '[email protected]')->named('category/date');
Then in your controller, set default values for those arguments:
public function getCategory($id = 1, $date = '2015-12-18')
{
// do your magic...
}
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad