I need help saving the name of the downloaded file in a database table using laravel 5.1.
My controller code for saving snapshot information
public function store(Request $request) { if($request->hasFile('img_filename')) { $destinationPath="offerimages"; $file = $request->file('img_filename'); $filename=$file->getClientOriginalName(); $request->file('img_filename')->move($destinationPath,$filename); } $input=$request->all(); Offer_image::create($input); return redirect('offerimage'); }
My view code for image reception
{!! Form::open(array('route'=>'offerimage.store','role'=>'form','files'=>true)) !!} <div class="box-body"> <div class="form-group"> {!! Form::label('img_name','Name') !!} {!! Form::text('img_name', $value = null, $attributes = array('class'=>'form-control','id'=>'img_name','required')) !!} </div> <div class="form-group"> {!! Form::label('img_description','Description') !!} {!! Form::textarea('img_description', $value = null, $attributes = array('class'=>'form-control','id'=>'img_description','required')) !!} </div> <div class="form-group"> {!! Form::label('img_filename','Upload Image') !!} {!! Form::file('img_filename') !!} </div> {!! Form::hidden('status',$value='active') !!} </div><!-- /.box-body --> <div class="box-footer"> {!! Form::submit('Submit',$attributes=array('class'=>'btn btn-primary')) !!} </div> {!! Form::close() !!}
This controller code is for saving the image correctly, but when I try to save the image file name in the table, this code stores the path to the database table.
Since I use the direct () method to store the query object in a table, I do not know how to save the file name instead of the path.
Check this image for table data.
source share