I've followed the docs here:
https://laravel.com/docs/5.8/validation#form-request-validation
I created a custom request StoreName
php artisan make:request StoreName
Then added the following validation rules:
public function rules()
{
return [
'name' => 'required|max:255|min:4'
];
}
Then as per the documentation type-hinted this in my controller:
public function store(StoreName $request)
{
$validated = $request->validated();
}
However, when I send a post request to this endpoint I'm returned a 403
from Laravel. When I remove the StoreName custom validation and simply type-hint the standard Laravel Illuminate\Http\Request
the request works fine (after removing the validated() method obviously).
So the 403 is coming from my custom validation request and I have no idea why? I've checked the file permissions on the StoreName.php file and they are the same as every other file in the project.
I'm using php artisan serve
for my development server so no funky Apache/Nginx configs overwriting things either. All other endpoints work apart from this one when the custom validation request is applied.
What could the problem be?
EDIT:
It's probably worth noting I've not changed the default authorize() method Laravel generates in the new custom request validation either:
public function authorize()
{
return false;
}
Laravel - Forbidden You don't have permission to access / on this server.
The most common cause of a 403 Forbidden Error is simply inputting an incorrect URL. As discussed before, many tightly secured web servers disallow access to improper URLs. This could be anything from accessing a file directory to accessing a private page meant for other users.
In your Custom request class you've got a method like this:
public function authorize()
{
return true; // this is false by default which means unauthorized 403
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With