0
So I was trying to use Laravel custom request, following the documentation:
api.php
Route::post('/register-user', [AuthController::class, 'register']);
AuthController.php:
namespace App\Http\Controllers;
use App\Http\Requests\TestRequest;
use Illuminate\Routing\Controller as BaseController;
class AuthController extends BaseController
{
/**
* Register a new user
* @param TestRequest $request
* @return void
*/
public function register(TestRequest $request): array
{
dd($request);
}
}
TestRequest.php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TestRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name' => 'required|string',
];
}
}
when I make a post request to this route, my $request object is just all empty. as you can see:
But when I change the TestRequest to just a regular Request, it works normally.
What am I missing using my custom TestRequest?