如何在“查看本地磁盘(Laravel)上的文件”上显示?

时间:2019-09-02 12:58:28

标签: laravel view storage

我想让文件存储在Laravel上。到目前为止,我使用php artisan storage:link命令进行了符号链接。当我保存文件时,它存储在目录“ storage / app / anexos /'filename.extension'”上。但是,当我尝试在视图上显示时,将显示错误404(未找到)。贝娄下面有一些截图。

查看时:

<div class="container mt-3">

        <img src="{{ asset("storage/app/anexos/$amostra->anexoURL") }}">

</div>

//$amostra->anexoURL is a nameFile that is saved on my table 'amostras'

在控制器上

        $nameFile = null;

        if ($request->hasFile('anexo') && $request->file('anexo')->isValid()) {

            $name = uniqid(date('HisYmd'));

            $extension = $request->anexo->extension();

            $nameFile = "{$name}.{$extension}";

            $upload = $request->anexo->storeAs('anexos', $nameFile);

            if ( !$upload )
                return redirect()
                            ->back()
                            ->with('error', 'Falha ao fazer upload')
                            ->withInput();
        }

        $url = $nameFile;

Saving a image, after that I get just name file and save on db on table amostra to make a relationship between the image and 'amostra'

On View

The address on inspector element browser

1 个答案:

答案 0 :(得分:0)

您正在使用的Asset()函数将在/ public文件夹中搜索,但是图像保存在/ storage文件夹中。 尝试使用:

<img src="{{ Storage::url($amostra->anexoURL) }}">