【发布时间】:2021-03-27 05:40:57
【问题描述】:
我有一页帖子。我添加了一个编辑图标,这样当我单击它时,它应该会显示编辑页面。但是,当我单击时,它会显示错误。
刀片/形状
<form method="POST" action="{{ route('post.update',
['id'=>$post->id]) }}" enctype="multipart/form-data">
@csrf
路线
Route::get('post/edit/{id}', 'PostController@edit')
->name('post.edit');
以下是 PostController 内部的edit() 方法。
public function edit($id)
{
$post = Post::find($id);
return view('posts.edit')->with('post', $post);
}
【问题讨论】:
-
您确定
$post不为空吗?尝试使用findOrFail()而不是find(),如果该 ID 未返回记录,则会出现 404。您可以在控制器中使用dd($post)或在视图中使用@dd($post)来查看实际传入的内容。
标签: laravel http-status-code-404 laravel-8