Hello, assuming you are using the same form.
I see this:
if ($request->hasFile('imagine')) {
with a SINGLE 'm'.
Shouldnt it be
if ($request->hasFile('immagine')) {
?
I've placed an image upload in my post in "Add new". But when i go to modify the element, the upload me from problems, with the error:
Call to a member function getClientOriginalExtension() on null
This is my code:
public function postAdd
$NomeImg = str_slug($slide->titolo, '-') . '.' .
$request->file('immagine')->getClientOriginalExtension();
$request->file('immagine')->move(base_path() . '/public/upload/news/', $NomeImg);
$slide->immagine = $NomeImg;
add.blade
{!! Form::label('Product Image') !!}
{!! Form::file('immagine') !!}
While the edit function:
public function postEdit
if ($request->hasFile('imagine')) {
$NomeImg = str_slug($slide->titolo, '-') . '.' .
$request->file('immagine')->getClientOriginalExtension();
$request->file('immagine')->move(base_path() . '/public/upload/news/', $NomeImg);
$slide->immagine = $NomeImg;
}
How do I replace an existing image if another is loaded?
You need to add this to your form: enctype="multipart/form-data"
You need to change this :
<form action="" method="post">
to
<form action="" method="post" enctype="multipart/form-data">
You should have this in your create.blade.php as well
Please or to participate in this conversation.