阿罗哈,我正在做一名健身经理,你有一个仪表板显示你最近的5次训练。我为每个锻炼设置了一个表单,允许用户删除其中任何一个。此处信息中心中的表单:
{!! Form::open(['route' => ['dashboard.workout.destroy', $workout->id], 'style' =>'display:inline-block;', 'method' => 'DELETE']) !!}
此路线将在 WorkoutController.php
中调用此方法public function destroy($id, Request $request)
{
$workout = Workout::findOrFail($id);
$workout->delete();
$message = "Workout deleted successfully!";
return redirect()->route('dashboard.index', ['message' => $message]);
}
此路线将在 DashboardController.php
中调用此方法public function index($message = null)
{
$user = Auth::user();
// Workouts
...
// Inbodies
...
// Measures
...
return view('dashboard.index', compact('user','workoutsDesc','workouts','lastInbody','inbodies','measures','lastMeasure','message'));
}
问题是我正在尝试将变量$ message从 WorkoutController 传递到 DashboardController ,以便在删除锻炼后显示成功警报,但我不知道知道怎么做。我尝试过:
return redirect()->action('Dashboard\DashboardController@index', [$message]);
return redirect()->action('Dashboard\DashboardController@index')->with('message', $message);
return redirect()->route('dashboard.index', $message);
但我仍然试图找到实现目标的方法。
答案 0 :(得分:0)
首先,来自Laravel 5.1 Documentation:
If your route has parameters, you may pass them as the second argument to the route method
由于邮件不是您路线的参数,因此您无法通过该邮件。可能的解决方案可以是Flashing data。如果会话具有该键并包含值,则检查下一个控制器,然后将其添加到变量并传递给视图。
希望这有效。