在laravel项目中,我尝试从数据库加载图像。但它显示断开的链接。但是,当我检查图像时,它显示了链接。但是,当我单击链接时,它显示404错误..... 这是我的密码
这是视图的代码 .............
@extends('layouts.app')
@section('content')
<div class="d-flex justify-content-end">
<a href="{{ route('posts.create') }}" class="btn btn-success mb-2">Add Posts</a>
</div>
<div class="card card-default">
<div class="card-header">Posts</div>
<div class="card-body">
<table class="table">
<thead>
<th>Image</th>
<th>Title</th>
</thead>
<tbody>
@foreach ($posts as $post)
<tr>
<td><img src="{{ asset($post->image) }}"></td>
<td>{{ $post->title }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
.............
这是控制器的代码
public function store(CreatePostsRequest $request)
{
//Upload the image
$image = $request->image->store('public/img');
//create the post
Post::create([
'title' => $request->title,
'description' => $request->description,
'content' => $request->content,
'image' => $image
]);
//flash a message with seasson
session()->flash('success','Post created successfully');
//redirect user
return redirect(route('posts.index'));
}
,我将存储链接到公用文件夹。但仍然无法正常工作
答案 0 :(得分:0)
您需要提供绝对路径,而不要使用{{asset ...}}。尝试这样的事情:
<img src="/xx/storage/app/public/FinalFolder/{{$post->image}}">