【发布时间】:2020-05-27 23:22:03
【问题描述】:
在 laravel 中,我必须使用 php artisan storage:link 链接存储,这样我就可以显示图像,当用户发布带有图像的文章时,图像将被显示。但现在,图像没有出现。我该如何解决。
这是来自views/post/index.blade.php的代码
<tbody>
@foreach($posts as $post)
<tr>
<td>
<img src="{{ asset($post->image) }}" alt="">
</td>
<td>
{{ $post->title }}
</td>
<td>
<a href=" {{ route('categories.edit', $post->category->id) }}">
{{ $post->category->name }}
</a>
</td>
当用户发布图像时,图像将存储在我之前所做的链接存储中。所以这是postscontroller.php 中的代码,如果我将“posts”更改为“post”,它会显示错误。因为我不适合我之前写的'posts'功能。
public function store(CreatePostRequest $request)
{
// upload image omegalul
$image = $request->image->store('posts');
// create the post
$post = Post::create([
'title' => $request->title,
'description' => $request->description,
'content' => $request->content,
'image' => $image,
'published_at' => $request->published_at,
'category_id' => $request->category,
'user_id' => auth()->user()->id,
]);
if ($request->tags) {
$post->tags()->attach($request->tags);
}
// flash a message
session()->flash('success', 'Post created successfully');
// redirect the user
return redirect(route('posts.index'));
}
如果你们发现我没有出现在这里的任何问题,请问我。非常感谢你们
【问题讨论】: