【发布时间】:2019-11-19 20:18:46
【问题描述】:
我想问当我删除一个需要重定向回topic.index但它是错误的主题时如何解决这个错误
(缺少 [Route: topic.index] [URI: topic/{id}/group] 的必需参数。)
follow show some code 01. in TopicController.
我尝试在TopicController 中添加$topic follow show some code 02.,它变为404 not found 和topic/{id}/group 之间的id 从Group 的id 变为已删除的Topic 的id
在 web.php
中Route::get('/topic/{id}/group', 'TopicController@index')->name('topic.index');
01.在主题控制器中
class TopicController extends Controller
{
public function index($id)
{
$group = Group::findOrFail($id);
$topics = Topic::where('group_id', $id)->orderBy('created_at', 'desc')->paginate(5);
return view('topic.index', compact('group', 'topics'));
}
public function destroy( Topic $topic)
{
if ($topic != null) {
$topic->delete();
return redirect()->route('topic.index') ; //*******
}
}
}
02.在主题控制器中
class TopicController extends Controller
{
public function index($id)
{
$group = Group::findOrFail($id);
$topics = Topic::where('group_id', $id)->orderBy('created_at', 'desc')->paginate(5);
return view('topic.index', compact('group', 'topics'));
}
public function destroy( Topic $topic)
{
if ($topic != null) {
$topic->delete();
return redirect()->route('topic.index',$topic) ; //*******
}
}
}
删除主题后我需要重定向回topic.index
我希望有人可以帮助我,我希望你能理解我的信息
【问题讨论】: