I'v created a form to update the table 'organizer'. My problem is that the image wont update. I've already added enctype="multipart/form-data"
to my form.
If I set the validation of the image to required, laravel throwes the error "The logo must be an image". It seems that my ImageController doesn't get the image file . But why does the Controller get all the other data like the description, name ..?
All the other data in the table 'organizer' is updating without problems!
Form
<form class="form" enctype="multipart/form-data" action="/organizer/update/">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="">
...
other input fields...
...
<label>Logo</label>
<input type="file" name="logo" id="logo" accept="image/*"/>
<button class="btn-add" type="submit">@lang('Save')</button>
</form>
Controller (only the code for updating the image)
if($request->hasFile('logo')){
// ADD NEW lOGO
$logo = $request->file('logo');
$logo_name = $request->name.'_logo'.time().'.'.$logo->getClientOriginalExtension();
$request->logo->move($destinationPath, $logo_name);
$oldFilename = $organizer->logo;
// UPDATE DATABASE
$organizer->logo = $logo_name;
// DELETE OLD lOGO
Storage::disk('public')->delete("organizer/$oldFilename.jpg");
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire