Intervention Image Upload Saved to Database with Folder Name
I am Try to Upload User Avatar with Intervention Image as below private function
Everything working fine but image name save to database with my specific folder name
eg : user_avatar/image.jpg
Here is My Code Thanks everyone
private function storeAvatar($user) { if (request()->hasFile('avatar')) { $user->update([ 'avatar' => request()->avatar->store('user_avatar', 'public'), ]); $avatar = Image::make(public_path('storage/'. $user->avatar))->fit(300, 300); $avatar->save(); } }
Try this:
private function storeAvatar($user)
{
if (request()->hasFile('avatar')) {
$file = $request->file('avatar');
$originalFilename = $file->getClientOriginalName();
$filePath = $file->storeAs('user_avatar', $originalFilename, 'public');
$image = Image::make(public_path('storage/' . $filePath))->fit(300, 300);
$image->save();
$user->update(['avatar' => $originalFilename]);
}
}
Hi, Thank for Reply, FileName saved to database as originalName but in public folder it saved by hash .Please help me check and thank again
https://prnt.sc/swzn4q
Hi @naysoewin
I have updated the answer, please try again.
Please or to participate in this conversation.