[英]I can't see my update profile image using laravel 6
i am trying to update the image of profil ,because to user at the beginning it creates account without image, after it goes the update, so i store the image in root /aswakfolder/public/storage/profiles
and i insert image link in db profiles/nameimage.jpeg
, i created a function in helpers.php
file to display the image its work very will, the problem here is that I do not understand the helpers function, and it does not meet my needs, my need is when image upload and exists it displays my image if not it displays image not-found.jpeg,in my case it always displays not-found.jpeg.我正在尝试更新 profil 的图像,因为用户在开始时它创建没有图像的帐户,更新后,所以我将图像存储在 root
/aswakfolder/public/storage/profiles
并在 db 中插入图像链接profiles/nameimage.jpeg
,我在helpers.php
文件中创建了一个函数来显示图像,它的工作非常好,这里的问题是我不理解 helpers 函数,它不满足我的需求,我的需要是当图像上传并存在它显示我的图像如果不是它显示图像not-found.jpeg,在我的情况下它总是显示not-found.jpeg。 stock image in my folder, and url image insert in db very well.我的文件夹中的库存图像,并且 url 图像在 db 中插入得很好。
UsersController.php用户控制器.php
public function update(Request $request, $id)
{
$user=User::find($id);
if($request->hasFile('image'))
{
$image = $request->file('image');
$path = $request->image->store('profiles');
$user->image = $path;
}
$request->image = $user->image;
$user->id = Auth::user()->id;
$user->update([
$user->name => $request->name,
$user->email => $request->email,
$user->telephone => $request->telephone,
$user->daten => $request->daten,
$user->country_id=> $request->country_id,
$user->state_id => $request->state_id,
$user->city_id => $request->city_id,
$user->image => $request->image,
]);
session()->flash('success', 'user updated successfully !!');
return redirect('users');
}
helpers.php帮助者.php
function productImage($path)
{
return $path && file_exists('/aswakfolder/public/storage/'.$path) ? asset('/aswakfolder/public/storage/'.$path) : asset('/aswakfolder/public/storage/not-found.jpg');
}
index.blade.php index.blade.php
<div class="inner" style="background-image: url({{ asset(productImage($users->image)) }})">
Make sure you run the commend php artisan storage:link
to create the shortcurt on public/
folder.确保您运行
php artisan storage:link
commcomm 在public/
文件夹上创建快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.