【问题标题】:404error in showing picture in laravel在laravel中显示图片时出现404错误
【发布时间】:2019-10-20 22:19:22
【问题描述】:

我想将图像保存在数据库中并显示给用户,但我收到 404 错误,这是我的错误:

获取 http://127.0.0.1:8000/Images/jgS4ITBpNmiKWEW6ex7oWzcNxmBxnZEvyNjokXxT.jpeg 404(未找到)

这是我的代码:

 public function store(Request $request)
    {
        $new_file_data=[
            'small_explain'=>$request->input('small_explain'),
            'title'=>$request->input('title'),
            'paragraph_one'=>$request->input('paragraph_one'),
            'paragraph_two'=>$request->input('paragraph_two'),
            'paragraph_list'=>$request->input('paragraph_list'),
            'paragraph_three'=>$request->input('paragraph_three'),
            'important_body'=>$request->input('important_body'),
            'quote'=>$request->input('quote'),
            'author_quote'=>$request->input('author_quote'),
            'index_image' => $request->file('index_image')->store('Images'),
            'header_image' => $request->file('header_image')->store('Images'),
            'text_image' =>$request->file('text_image')->store('Images'),
        ];
        Article::create($new_file_data);
    }

welcome.blade.php

@foreach( $recentArticles as $article)
                    <div class="work-detail">
                        <a href="home-restaurant.html">
                            <img src="{{ $article->index_image }}" alt="">
                            <div class="work-info">
                                <div class="centrize">
                                    <div class="v-center">
                                        <h3>{{ $article->title }}</h3>
                                        <p> {{ $article->small_explain }} </p>
                                    </div>
                                </div>
                            </div>
                        </a>
                    </div>
@endforeach

【问题讨论】:

  • 请在显示图片的地方添加view.blade

标签: php laravel


【解决方案1】:
   <img src="{{ $article->index_image }}" alt="">

改成

<img src="{{ asset('/your custom path/' .$article->index_image) }}" alt="">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-19
    • 2017-07-07
    • 1970-01-01
    • 2014-12-31
    • 2021-06-16
    • 2019-03-31
    • 1970-01-01
    • 2020-10-01
    相关资源
    最近更新 更多