Please show your validation code, and how you're uploading the file, otherwise people can't really help you.
File validation error
I have a form with a pdf upload field which has pdf only validation. If I try to upload another file type I don't get a validation error but a MethodNotAllowedHttpException. Why is that happening?
My validation:
class ApplyValidation extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'cv' => 'mimes:pdf',
];
}
}
My form:
<form action="{{ route('apply.store') }}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="cv">CV <small> PDF ONLY</small> </label>
<input type="file" class="form-control-file" name="cv" id="cv">
</div>
<button type="submit" class="btn btn-primary">SUBMIT</button>
</form>
Controller? Routes file?
Route:
Route::post('/apply_store',[
'uses' => 'ApplyController@store',
'as' => 'apply.store'
]);
Controller:
public function store(ApplyValidation $request){
$apply = new Apply;
if($request->hasFile('cv')){
\Cloudder::upload($request->file('cv'));
$cv = \Cloudder::getResult();
if($cv){
$apply->cv = $cv['url'];
}
}
$apply->save();
return view('home');
}
I am using cloudinary for file uploading
I forgot about the routes file, that would also be helpful to see. I'm guessing you made the route a GET route, and you're trying to POST, which is probably why you're getting the MethodNotAllowedHttpException.
Nevermind what I just said, you posted just right before I did.
No my route is actually set to POST, but i think it may have something to do with the cloud service i'm using. When I hit back from the error page I see the error that was supposed to appear.
dd($request->all()); just before the $apply = new Apply; line and dump here the output.
It doesn't dump the data, the exeption appears only. But when I upload a correct pdf file it dumps the data correctly including the file. I'm just guessing the error may be caused by cloudinary.
I also use Cloudder package which allows me to use cloudinary in Laravel
Please or to participate in this conversation.