我正在尝试删除带有下拉链接“删除帖子”的用户帖子。我也想删除照片,因此我有逻辑上的权利。我不明白我在做什么错。如果有人可以指导我,将不胜感激。
PostsController:
<?php
public function destroy($id)
{
$post = Post::findOrFail($id);
unlink(public_path() . $post->photo->file);
$post->delete();
return redirect('/home');
}
web.php:
Route::delete('/home', 'PostsController@destroy')->name('deletePost');
home.blade.php:
<div class="card-header">
<div class="dropdown">
<button style="float: right;" type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Edit Post</a>
<a class="dropdown-item" href="{{ route('deletePost') }}">Delete Post</a>
</div>
</div>
<div>{{$post->user->name}}</div>
<div id="post-date">{{$post->created_at->diffForHumans()}}</div>
</div>
答案 0 :(得分:0)
只需将路线更改为
Route::get('/home', 'PostsController@destroy')->name('deletePost');
因为标签a
发出了http GET请求,而您正在列出DELETE请求