Reputation: 2000
i want to store image in my database as client agreement but i can't save any thing in database just the path i give manually here is what i have done
controller :
$filename = $request->file('agreement')->store('public/images');
$client = Client::create([
'title' => $request->title,
'description' => $request->description,
'fax'=>$request->fax,
'adrress1'=>$request->adrress1,
'telephone1'=>$request->telephone1,
'client_type'=>$request->client_type,
'sellpercent'=>$request->sellpercent,
'agreement'=>'uploads/agreement/'. $filename,
view :
.
.
.
<div class="form-group row">
<label class="col-form-label col-lg-2">test image</label>
<div class="col-lg-10">
<input type="file" name="agreement" class="form-control-plaintext">
</div>
</div>
<button type="submit" class="btn btn-primary btn-raised legitRipple">submit</button>
with this code i get this error on store function
Call to a member function store() on null
and if i remove store function i just save null in database
Upvotes: 0
Views: 576
Reputation: 307
Firstly add enctype='multipart/form-data'
in your form tag as an attribute.
Secondly,
replace $filename = $request->file('agreement')->store('public/images');
with $filename = $request->file('agreement')->move('public/images');
Hope that helps.
Upvotes: 1