尝试使用路由功能在内部发送多个键值:Laravel 5.2
Trying to send multiple Key value inside with function for a Route: Laravel 5.2
我正在使用以下函数发送键值以显示基于数据库操作的消息。
return redirect()->route("Roles")->with("UpdateRole", "updated");
现在,我也想发送一个状态代码密钥,但根据 with function 的文档,我们可以发送一个密钥及其对应的值。
有什么方法可以发送多个Key及其对应的值吗?
正在查看Laravel API:
RedirectResponse with( string|array $key, mixed $value = null)
这应该有效:
return redirect()->route("Roles")->with([
"key1" => "value1",
"key2" => "value2"
]);
你要的就是所谓的刷机数据。 Redirecting With Flashed Session Data引入主题。
没有明确但可能的是使用多个 ->with()
。
return redirect()->route("Roles")
->with("page_view_time", date("Y-m-d H:i:s"))
->with("user_name", $user->name);
此外,@AlexandreThebaldi said, the Laravel API 表明可以使用数组(一定要使用关联数组)。
return redirect()->route("Roles")
->with('alerts', [
'success' => 'Congratulations! Account created.',
'info' => 'Check your email to verify your account.'
])
->with([
'user_name' => $user->name,
'user_score' => $user->score,
'highest_score' => $highest_score
]);
重要的是要记住,您必须知道您将在 blade 模板中获得什么,例如数组或字符串/数字。
我正在使用以下函数发送键值以显示基于数据库操作的消息。
return redirect()->route("Roles")->with("UpdateRole", "updated");
现在,我也想发送一个状态代码密钥,但根据 with function 的文档,我们可以发送一个密钥及其对应的值。
有什么方法可以发送多个Key及其对应的值吗?
正在查看Laravel API:
RedirectResponse with( string|array $key, mixed $value = null)
这应该有效:
return redirect()->route("Roles")->with([
"key1" => "value1",
"key2" => "value2"
]);
你要的就是所谓的刷机数据。 Redirecting With Flashed Session Data引入主题。
没有明确但可能的是使用多个 ->with()
。
return redirect()->route("Roles")
->with("page_view_time", date("Y-m-d H:i:s"))
->with("user_name", $user->name);
此外,@AlexandreThebaldi said, the Laravel API 表明可以使用数组(一定要使用关联数组)。
return redirect()->route("Roles")
->with('alerts', [
'success' => 'Congratulations! Account created.',
'info' => 'Check your email to verify your account.'
])
->with([
'user_name' => $user->name,
'user_score' => $user->score,
'highest_score' => $highest_score
]);
重要的是要记住,您必须知道您将在 blade 模板中获得什么,例如数组或字符串/数字。