【发布时间】:2021-09-22 13:11:39
【问题描述】:
我试图将我的删除功能重定向回具有参数团队的索引页面。但它不断向我抛出错误异常数组到字符串的转换。 这是我在 MonitorController.php 上的索引功能
public function index(Team $team)
{
$team = Team::where('id',$team->id)->first();
$objective = Objective::with('keyresult')
->where('team_id',$team->id)
->get();
$objective = Objective::with('task')
->where('team_id',$team->id)
->get();
$objective = Objective::with('deadline')
->where('team_id',$team->id)
->get();
return view('/sistem/monitor/index', compact('objective','team'));
}
这是我在同一文件 MonitorController.php 中的删除函数
public function destroy(Team $team, Objective $objective, Deadline $deadline)
{
//for deleting objective
Objective::destroy($objective->id);
Deadline::destroy($deadline->id);
return redirect()->action([MonitorController::class, 'index',['team'=>$team]])->with('status', 'Objective Successfully Deleted');
}
这里是索引和销毁路径
Route::get('/sistem/monitor/index/{team}', 'MonitorController@index');
Route::delete('/sistem/monitor/objective/details/{team}/{objective}', 'MonitorController@destroy');
【问题讨论】:
-
你可以做 return redirect()->route('your_route_name')->with('status', 'Objective Successfully Deleted');
-
你能详细说明一下吗?我尝试返回 redirect()->route('sistem/monitor/index/team', 'MonitorController@index');但我得到 Symfony\Component\Routing\Exception\RouteNotFoundException Route [/sistem/monitor/index/{team}] 未定义。
-
我在上面回答了
标签: laravel redirect routes destroy