来自 cpanel 的 Laravel 项目的图像路径

Path for images for Laravel project from cpanel

我在 Laravel 中的项目的视图中显示图片时遇到问题..我的应用程序中保存照片的目标路径是:public_path (/ images) 但最近我把在 cpanel 中服务器上的项目,为了从 url 中删除 /public,我使用了一篇 google 文章,并在public_html 文件夹,我在其中保存应用程序文件,而在 public_html 中,我仅保留应用程序 public 文件夹中的文件。在视图中我显示图片如下:“{{asset ('images /'.$ Img-> file_name)}}” ..只是它不再显示了。图片已保存但不再显示。我提到它保存在 public_html 文件夹外的 Laravel 文件夹中..我认为 public / images 是在那里自动创建的..我想知道是否有人遇到过这样的事情,解决方法是什么。谢谢

我是这样解决问题的: 在 AppServiceProvider 的 register() 中,我输入了这段代码:

$this->app->bind('path.public', function () {
        return base_path('../public_html');
    });

现在我有 public_html/images 并且我的图像保存在那里..我的应用程序的其余部分在 public_html 文件夹之外的另一个名为 laravel_project[=11= 的文件夹中]

在 Laravel 8 中,我解决了它,将其添加到注册方法中的 /app/Providers/AppServiceProvider.php:

public function register()
{
    $this->app->bind('path.public', function () {
        return base_path('../public_html');
    });
}

但是为了从“php artisan storage:link”命令创建符号链接,我还必须将此代码添加到 /bootstrap/app.php,就在最后一个单例之后:

$app->bind('path.public', function () {
    return base_path("../public_html");
});

最后我使用此代码获取将发送到我的 blade 模板的图像:

$image=Storage::disk('public')->url('path_to_image');