从Laravel图片网址中删除“存储" [英] Remove 'storage' from Laravel image url

查看:80
本文介绍了从Laravel图片网址中删除“存储"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将一张图像上传到服务器,除我需要在URL中添加storage以便从Laravel的公共目录访问图像之外,其他所有操作均已正确设置.

I have uploaded one image to server, everything is set up correctly except I need to add storage in the URL to access images from public directory of Laravel.

https://example.com/a/xyz.png -无法访问

https://example.com/storage/a/xyz.png -可访问

但是在本地,可以访问没有存储的URL.

But in local the URL without storage is accessible.

NGINX

root /var/www/example.in/live/public/;
index index.html index.php index.htm index.nginx-debian.html;
server_name example.in www.example.in;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
        deny all;
}

这不是我需要从URL隐藏存储单词的问题.我的问题是图像的URL默认情况下应该在没有存储字的情况下工作.它不起作用.在我的本地计算机上,由代客管理的相同代码在没有存储关键字的情况下可以正常工作

This is not the issue where I need to hide storage word from the URL. My problem the URL of image should work without the storage word by default. It is not working. The same code on my local machine which is managed by valet, is working fine without storage keyword

推荐答案

事情是,通过执行命令php artisan storage:link,它应该位于该位置(即public_path('storage')).这是默认行为.您可以通过以下方式手动链接到所需位置:

Thing is that with executing command php artisan storage:link it's supposed to be on that location (i.e. public_path('storage')). It's default behaviour. You can link manually to wanted location as:

ln -s /absolute/path/to/project_root/storage/app/public /absolute/path/to/project_root/public/wanted-name-of-directory

或使用自定义命令扩展本机命令.对于后一种解决方案,请遵循此答案中的逻辑.应该是这样的:

or to extend native command with custom one. For latter solution, follow logic from this answer. It should be like:

  1. php artisan make:command CustomStorageLinkCommand

然后从新创建的文件中删除所有文件并使用此代码:

Then delete all from newly created file and use this code:

<?php

namespace App\Console\Commands;

use Illuminate\Foundation\Console\StorageLinkCommand;

class CustomStorageLinkCommand extends StorageLinkCommand
{
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a symbolic link from "public/a" to "storage/app/public"';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        if (file_exists(public_path('a'))) {
            return $this->error('The "public/a" directory already exists.');
        }
        $this->laravel->make('files')->link(
            storage_path('app/public'), public_path('a')
        );
        $this->info('The [public/a] directory has been linked.');
    }
}

  1. 执行php artisan storage:link命令

这篇关于从Laravel图片网址中删除“存储"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆