laravel 请帮助我与我的代码,我该怎么做,我粘贴的照片使用资产< img src=" ? ">

yjghlzjz  于 2023-08-08  发布在  其他
关注(0)|答案(3)|浏览(67)
@foreach ($profiles as $profile)
        <tr>
            <td>{{ $profile->id }}</td>
            <td>{{ $profile->email }}</td>
            <td>{{ $profile->name }}</td>
            <td>{{ $profile->age }}</td>
            <td>{{ $profile->gender }}</td>
            <td>{{ $profile->position }}</td>
            <td>{{ $profile->department }}</td>
            <td>{{ $profile->phone_number }}</td>
            <td>
                @if ($profile->images)
   **             <img src="{{ asset('storage/app/public/'.$profile->images) }}" alt="Profile Image"
                    style="max-width: 50px; border-radius: 50%;">**
                @else
                No Image
                @endif
            </td>

字符串
我已经尝试在资产中使用URL,但它根本不起作用,我已经使存储文件夹变短,但它对我没有任何帮助

lnvxswe2

lnvxswe21#

我认为你没有正确地将它与资产和前缀联系起来。尝试
它将在public/storage文件夹中查找映像,您可以在其中定义自己的映像文件夹

<img src="{{ Storage::url($pathToImage) }}"

字符串

cl25kdpy

cl25kdpy2#

请检查以下步骤:
1.尝试保存图像位置的绝对而不是相对的URL位置在这种情况下,你应该只是把图像的URL位置指令

<img src="{{$profile->images}}" alt="Profile Image" style="max-width: 50px; border-radius: 50%;">

字符串
1.如果你想在相对模式下保存位置,首先在laravel中检查存储是否连接到你项目,你可以用途:
php artisan storage:link
在Linux中,您可以用途:
ln -s /storagelocation public/storage
然后用你的代码显示img

<img src="{{ asset('storage/app/public/'.$profile->images) }}"Alt="Profile Image" style="max-width: 50px; border-radius: 50%;">

46scxncf

46scxncf3#

你可以检查这些东西:
1.检查.env文件和APP_URL值:它应该是https://[yourwebsite.com]-有些人忘记将其从默认的localhost更改,或者提供错误的URL和额外的文件夹/子域
1.如果您在storage/app/public中存储图像,请检查您是否已运行php artisan storage:link成功(因此,没有发生错误)以创建符号链接。
1.检查您的Web服务器根文件夹是否成功指向Laravel项目的/public文件夹。
1.然后,您可以使用asset('storage/'.$profile->images)调用这些storage/app/public图像
查看这里的文档:https://laravel.com/docs/10.x/filesystem#the-public-disk
顺便说一下,我会将变量从images重命名为image,因为它似乎是一个单一的图像,可能会被未来的开发人员误解。

相关问题