Level 54
i guess that the $data->warrantyUpload you get from DB is a string... try remove this...
value="{{$data->warrantyUpload}}"
Getting this error after updating the image.
Call to a member function getClientOriginalExtension() on string
This is the before code. If I dd(); this code I get the file name with the extension but it's a string. So I cannot get the original extension.
$image = $request->warrantyUpload;
$destination = public_path('/uploads/');
$ext = $image->getClientOriginalExtension();
$mainFilename = "img_".rand(111111,999999);
$image->move($destination, $mainFilename.".".$ext);
$image->warrantyUpload = $mainFilename.".".$ext;
$data->warrantyUplaod = $image->warrantyUpload;
$data->save();
I changed my code to this. If I dd(); this code I don't get anything. Just a NULL.
$image = $request->file('warrantyUpload');
$destination = public_path('/uploads/');
$ext = $image->getClientOriginalExtension();
$mainFilename = "img_".rand(111111,999999);
$image->move($destination, $mainFilename.".".$ext);
$image->warrantyUpload = $mainFilename.".".$ext;
$data->warrantyUplaod = $image->warrantyUpload;
$data->save();
And the error now is :
Call to a member function getClientOriginalExtension() on null
I have also tried 'PATCH' and 'PUT' both methods.
This is View Code :
<form action="{{ route('assets.update', $data->_id)}}" method="POST" enctype="multipart/form-data">
@csrf
@method('PATCH')
<div class="form-group col-10">
<label for="warrantyUpload">Warranty Card:</label>
<input type="file" class="form-control p-1" required="required" value="{{$data->warrantyUpload}}" name="warrantyUpload">
</div>
<div class="form-group col-10">
<button type="subumit" class="btn btn-primary">Submit</button>
</div>
</form>
i guess that the $data->warrantyUpload you get from DB is a string... try remove this...
value="{{$data->warrantyUpload}}"
Please or to participate in this conversation.