when I am trying to upload an image there is no error being shown or anything coming out. All it does was return me back to the create1.blade.php. When I try to use dd, it also doesn't show anything as well(maybe I put it wrongly or something not sure, still learning about it)
Here are my codes:
Controller:
public function create1(){
return view('create1');
}
public function store1(Request $request){
$this->validate($request, [
'input_img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($request->hasFile('input_img')) {
$image = $request->file('input_img');
$name = time().'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$image->move($destinationPath, $name);
$this->save();
return redirect()->back()->with('success','Image Upload successfully');
}
}
create1.blade.php
<form class="form-horizontal" method="post" action="{{ url('/userUpload')}}">
{{ csrf_field() }}
<div class="form-group">
<label for="imageInput" class="control-label col-sm-3">Upload Image</label>
<div class="col-sm-9">
<input data-preview="#preview" name="input_img" type="file" id="imageInput">
<img class="col-sm-6" id="preview" src="" ></img>
</div>
</div>
<div class="form-group">
<div class="col-md-6-offset-2">
<input type="submit" class="btn btn-primary" value="Save">
</div>
</div>
</form>
You just forgot to put enctype="multipart/form-data"
in your <form>
tag!
This is allow to upload the file!
For example:
<form class="form-horizontal" method="post" action="{{ url('/userUpload')}}" enctype="multipart/form-data">
Hope this fixed your issue!
The issue is here:
<form class="form-horizontal" method="post" action="{{ url('/userUpload')}}">
here you are missing enctype="multipart/form-data"
. Put it in form like:
<form class="form-horizontal" method="post" action="{{ url('/userUpload')}}" enctype="multipart/form-data">
and try again.