W
W
wideShift2021-04-09 14:42:48
Laravel
wideShift, 2021-04-09 14:42:48

Why in the controller method to specify the Request type for the argument?

Here is a controller method in Laravel, why specify the Request type? I understand why this is needed here (with a simple type):
public function store(Request $request) { }

function test(int $x) {
  return $x;
}
var_dump(test(1.6)); // 1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Edwardkv, 2021-04-09
@wideShift

For Request $request in Laravel, you can define validations by creating your own Request.
php artisan make:request StorePostRequest
Read https://laravel.com/docs/8.x/validation#creating-f...
And much more can Request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question