Store : in controller
public function store(Request $request)
{
$image='';
if(!empty($request->file('image')))
{
$file=$request->file('image');
$path=base_path().'/public/article_upload';
$name=uniqid().'_'.$file->getClientOriginalName();
if($file->move($path,$name))
{
$image=$name;
}
}
// $input = $request->except('image');
$input = $request->all();
$input['image'] = $image;
$status=article::create($input);
if($status){
Session::flash('success','customer_card added successfully.');
}else{
Session::flash('error','customer_card cannot be added.');
}
return redirect('backend/article');
}
In Create Blade:
<div class="form-group">
<label for="image">Image</label>
<input type="file" name="image" id="image" class="form-control dropify" >
</div>
Updating :in controller:
public function update(Request $request, About $about)
{
$input = $request->all();
$image='';
if(!empty($request->file('image')))
{
$file=$request->file('image');
$path=base_path().'/public/about_upload';
$name=uniqid().'_'.$file->getClientOriginalName();
if($file->move($path,$name))
{
$image=$name;
$input['image'] = $image;
}
}
$status=$about->update($input);
if($status){
Session::flash('success','Imformation Updated successfully.');
}else{
Session::flash('error','Information Cannot be Update');
}
return redirect('home');
}
In edit.blade:
<div class="form-group">
<input type="hidden" name="image" id="image" class="form-control" value="{{$member->image}}" >
<label for="image">Change image</label>
<input type="file" name="image" id="image" class="form-control dropify" value="{{$member->image}}">
<td><img src="{{asset('/member_upload/'.$member->image)}}" height="100" width="100"></td>
</div>
Comments
Post a Comment