Are you sure that it's Laravel and not your webserver/PHP configuration that stops you?
May 22, 2020
6
Level 8
Laravel validation odd behavior
I'm working on a file upload and it upload well until I try to get a file I'm not supposed to be able to upload.
My rules are:
public function rules()
{
return [
'media' => ['required', 'image', 'max:2000']
];
}
public function messages()
{
return [
'media.required' => 'You must give a file to upload!',
'media.image' => 'The file is not an image!',
'media.max' => 'The file is too big!',
];
}
and when I try to upload a file which is 2,3Mo I got a 422 but the message is always The given data is invalid without telling me which one is invalid.
Then in my controller, this is how I use it:
public function uploadMedia(AddMediaRequest $request, MyEntity $entity)
{
$filename = $entity->addMedia($request->validated());
return response()->json(['filename' => $filename], 200);
}
Am I missing a simple point ? (I use Vue for the front end with axios)
Please or to participate in this conversation.