In web.php file I have route like this:
Route::get('/list/{list_id}/edit', [ListingController::class, 'edit']);
Then in ListingController:
public function edit(Request $request) {
var_dump($request->list_id);
var_dump($request->filled('list_id'));
exit;
}
If url is like: domain.com/list/20/edit
result is: string(2) "20" bool(false)
So $request->list_id
exists but $request->filled('list_id')
gives FALSE. What is reason for that?
(P.S. If pass parameter as usual GET parameter like ?list_id=20
then filled() method gives TRUE).
2
Answers
This is because the
filled()
method is specifically designed to check if a value is present in the request’s input data, which includes query parameters, form data, and JSON data, but not route parameters.Instead you should try using the
has()
method like:If you use it as a parameter in your route like
domain.com/list/20/edit
you need to specify it in your method:You can also omit the
Request
here as it is no longer used:See this example in the laravel documentation on basic controllers