如何从Laravel Homestead中的存储文件夹访问图像(符号链接问题?)>

问题描述 投票:0回答:1

我试图弄清楚如何访问存储的文件,在这种情况下为个人资料图片。

理想情况下,我想将它们保存在“ profilepictures”文件夹中。可以使用指向storage / app / public / profilepictures的符号链接位于public / profilepictures目录中]

我的代码现在看起来如下:

控制器:

    //store our image in the profilepics directory
    $profilepicpath = request('profilepic')->store('profilepictures', 'public');

    //actually write all the data to the database
    auth()->user()->profile()->create([
        'profilepic' => $profilepicpath,
        'dateofbirth' => $data['dateofbirth'],
        'about' => $data['about'],
        'zipcode' => $data['zipcode'],
        'state' => $data['state']
    ]);

查看:

<div class="data" style="visibility: hidden;">
    {{$profile = App\profile::find(Auth::user()->id)}}
</div>
    <div class="profile-wrapper">
        <div class="profile-grid">
            <div class="profilepic">
            <img class="profilepic-image" src={{asset($profile['profilepic'])}}>
            </div>

Config中的Filesystems.php:

/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/

'links' => [
    //public_path('storage') => storage_path('app/public'),
    public_path('profilepictures') => storage_path('app/public/profilepictures'),
],

任何人都知道为什么这不起作用?

下面我可以确认有一个符号链接,它似乎指向正确的位置:Viewing Symbolic Link in Terminal

如果我从应该在视图中显示的位置复制图像位置,则会得到以下之一:

enter image description here

enter image description here

这两个链接都不起作用,如果我尝试在浏览器中访问它,只会收到错误404。尽管基于查看目录结构,我认为第一个应该起作用。

enter image description hereenter image description here

有人有什么建议吗?

我正在ubuntu物理桌面上安装的virtualbox vm的homestead上运行laravel,到目前为止,我已经为此尝试了许多不同的配置,包括编辑.htaccess文件都没有成功。

我试图弄清楚如何访问存储的文件,在这种情况下为个人资料图片。理想情况下,我想将它们保存在“ profilepictures”文件夹中。可以在public / profilepictures目录中...

php laravel symlink public homestead
1个回答
0
投票

好,在这个特定实例中,唯一的问题是,当我第一次运行php artisan storage:link命令时,我是从主机而不是VM运行它的。因为我使用的是Homestead(vm),需要做的是无所事事的销毁,然后重新创建VM,并从VM终端运行php artisan storage:link命令,并且运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.