问题描述
我试图将我的删除功能重定向回具有参数团队的索引页面。但它不断向我抛出错误异常数组到字符串转换。 这里是我在 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');
解决方法
Route::get('/sistem/monitor/index/{team}','MonitorController@index')->name('sistem.monitor.index');
在你的控制器中:
return redirect()->route('sistem.monitor.index',['team' => $team])->with('status','Objective Successfully Deleted');
在路线内,您应该始终传递路线名称。在 web.php 上的路由中,通过执行以下操作指定自定义路由名称:->name('sistem.monitor.index')