[英]Laravel 5.3 - flash data removed after redirect
I am using Laravel 5.3 我正在使用Laravel 5.3
I have two models, Parent
and Student
with a many-to-many relationship between them and I want to add a Parent
for a Student
and vice versa. 我有两个模型,
Parent
和Student
,他们之间有多对多关系,我想为Student
添加Parent
,反之亦然。
My approach was: 我的方法是:
Create a link from Student
profile to add Parent
, like so: 从
Student
配置文件创建一个链接以添加Parent
,如下所示:
<a href="{{ route('students.parents.add', ['id' => $student->id]) }}" title="Add parent">Add Parent</a>
Add the route students.parents.add
with a controller method to flash the id
to the session and redirect. 使用控制器方法添加路线
students.parents.add
,将id
刷新到会话并重定向。
// in web.php: Route::get('/students/{id}/parents/add', ['as' => 'students.parents.add', 'uses' => 'StudentController@addParent']); Route::resource('students', 'StudentController'); // and in StudentsController: public function addParent($id) { return redirect()->route('parents.create')->with('associated_id', $id); }
After that, clicking the button redirects to the ParentsController
create()
but the session data is not there when I try return session()->all()
. 之后,单击按钮会重定向到
ParentsController
create()
但是当我尝试return session()->all()
时会话数据不存在。
Am I missing something? 我错过了什么吗?
Make sure you are not adding web
middleware in your routes.php
file as it is already added in the file RouteServiceProvider.php
file. 请确保您不添加
web
在您的中间件routes.php
的文件,因为它是在文件已经添加RouteServiceProvider.php
文件。
If you now apply it again in your routes.php, you will see that web appears twice on the route list php artisan route:list
. 如果您现在再次在routes.php中应用它,您将看到该网站在路线列表
php artisan route:list
上出现两次。 This exactly makes the flash data discard. 这确实使闪存数据丢弃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.