In Laravel, you can define route parameters using curly braces {} in your route definitions.
These parameters allow you to capture values from the URL and pass them to your controller methods for further processing.
Here's a basic example of how to define and use route parameters in Laravel:
Route::get('/user/{id}','UserController@show');
In this example, {id} is a route parameter that will capture whatever value is in the URL segment at that position.
1) Parameters must be pass alphabet other wise give 404
=> example
Route::get('/user/{name}', function ($name) {
})->where('name', '[A-Za-z]+');
2) must be pass numeric parameters
Route::get('/user/{id}', function ($id) {
//
})->where('id', '[0-9]+');
3) must be pass numeric and name must be alphabet parameters
Route::get('/user/{id}/{name}', function ($id, $name) {
//
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
For convenience, some expression patterns have helper methods
Route::get('/user/{id}/{name}', function ($id, $name) {
//
})->whereNumber('id')->whereAlpha('name');
Route::get('/user/{name}', function ($name) {
//
})->whereAlphaNumeric('name');
Route::get('/user/{id}', function ($id) {
//
})->whereUuid('id');
Route::get('/user/{id}', function ($id) {
//
})->whereUlid('id');
Pls follow in instagram
Route::get('/category/{category}', function ($category) {
//
})->whereIn('category', ['movie', 'song', 'painting']);
No comments:
Post a Comment