Level 122
try instead;
Team::create($request->except(['photo','showOnHome']) + ['photo'=>$fileName,'showOnHome'=> $request->has('showOnHome')]);
and remove the merge commands
1 like
I am using a Separate Class to upload my images in Laravel. The image files successfully get uploaded in the desired location but the filename in database is stored as C:\xampp\tmp\php1A3F.tmp.
Controller
// Store Method inside Team Controller
public function store(TeamRequest $request, SingleImageUpload $singleImageUpload) {
$file = $request->file('photo');
try {
$fileName = $singleImageUpload->store($file, getcwd() . '/images/teams/', 400, 400);
$request->merge(['photo' => $fileName]);
$request->has('showOnHome')
? $request->merge(['showOnHome' => 1])
: null;
Team::create($request->all());
return back()->with('success', 'Team Member Added Successfully.');
} catch (Throwable $throwable) {
return back()->with('error', 'Something went wrong. Please try again or contact administrator.');
}
}
ImageUploader Class
class SingleImageUpload {
public function store($file, $path, $width, $height) {
$fileName = 'protechimage'.time().'.'.$file->getClientOriginalExtension();
Image::make($file)
->fit($width, $height)
->save($path . $fileName, 100);
return $fileName;
}
}
try instead;
Team::create($request->except(['photo','showOnHome']) + ['photo'=>$fileName,'showOnHome'=> $request->has('showOnHome')]);
and remove the merge commands
Please or to participate in this conversation.