working with laravel 5.6 and I have images update function in My edit.blade.php file,
edit.blade.php
<img id="preview"
src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
height="200px" width="200px"/>
<input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
<br/>
and My update Controller is
$photos = $request->file('files');
if (!is_array($photos)) {
$photos = [$photos];
}
if (!is_dir($this->photos_path)) {
mkdir($this->photos_path, 0777);
}
for ($i = 0; $i < count($photos); $i++) {
$photo = $photos[$i];
$name = sha1(date('YmdHis') . str_random(30));
$save_name = $name . '.' . $photo->getClientOriginalExtension();
$resize_name = $name . str_random(2) . '.' . $photo->getClientOriginalExtension();
Image::make($photo)
->resize(250, null, function ($constraints) {
$constraints->aspectRatio();
})
->save($this->photos_path . '/' . $resize_name);
$photo->move($this->photos_path, $save_name);
$upload = Upload::find($id);
$upload->filename = $save_name;
$upload->resized_name = $resize_name;
$upload->original_name = basename($photo->getClientOriginalName());
$upload->vehicle_id = $vehicle->id;
$upload->save();
}
My problem is when I go to edit form and edit some onother field values without image edit (existing images) and click update buttons generated following error message,
1/1) FatalErrorException
Call to a member function getClientOriginalExtension() on null
in VehicleController.php line 376
VehicleController.php line 376 is this,
$save_name = $name . '.' . $photo->getClientOriginalExtension();
how can I fix this problem?