I hope this
The file under validation must be an image (jpeg, png, bmp, gif, or svg)
and this https://laracasts.com/discuss/channels/laravel/image-validation-the-profile-picture-must-be-an-image?page=1 will help you out.
I am testing image upload via PHPunit by calling a route (/admin/articles) which uses a controller (ArticleController) to upload an image.
$data = [
'heroImage' => UploadedFile::fake()->image('test_image.jpg')
];
// Call a controller via route
$response = $this->actingAs($user)->call('POST', '/admin/articles', $data);
In my ArticleController I have a validation rule
$this->validate($request, [
'heroImage' => 'image|mimes:jpg,png'
]);
When I run tests without the validation rule they pass, but when I add the validation rule they fail.
What am I doing wrong?
Thank you!
Either change it to 'image|mimes:jpeg,png' or 'image|mimetypes:image/jpeg,image/png'
Please or to participate in this conversation.