数据未通过重定向传递
Data is not being passed with redirect
下面是重定向到路由的代码。我正在尝试使用 $success 在视图中获取成功变量,但它给出了错误 "Undefined variable: success"。我还尝试将数组格式的数据传递给 with 方法。我该如何更正它?
if ($data->save())
return redirect('/cases/ppost/notification')->with('success', 'Your case has been posted.')->with('caseNo', $data->id);
不会吧??
Redirect::route('/cases/ppost/notification')->with( array('success'=>'Your case has been posted.','caseNo'=>$data->id)) ;
根据文档,redirect()->with()
方法不会将任何数据分配给您的视图,而是将其闪烁到会话中:
http://laravel.com/docs/5.0/responses#redirects
Returning A Redirect With Flash Data
Redirecting to a new URL and flashing data to the session are
typically done at the same time. So, for convenience, you may create a
RedirectResponse instance and flash data to the session in a single
method chain:
return redirect('user/login')->with('message', 'Login Failed');
这意味着您必须在您的视图中按原样访问它。那可能看起来像这样:
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif
下面是重定向到路由的代码。我正在尝试使用 $success 在视图中获取成功变量,但它给出了错误 "Undefined variable: success"。我还尝试将数组格式的数据传递给 with 方法。我该如何更正它?
if ($data->save())
return redirect('/cases/ppost/notification')->with('success', 'Your case has been posted.')->with('caseNo', $data->id);
不会吧??
Redirect::route('/cases/ppost/notification')->with( array('success'=>'Your case has been posted.','caseNo'=>$data->id)) ;
根据文档,redirect()->with()
方法不会将任何数据分配给您的视图,而是将其闪烁到会话中:
http://laravel.com/docs/5.0/responses#redirects
Returning A Redirect With Flash Data
Redirecting to a new URL and flashing data to the session are typically done at the same time. So, for convenience, you may create a RedirectResponse instance and flash data to the session in a single method chain:
return redirect('user/login')->with('message', 'Login Failed');
这意味着您必须在您的视图中按原样访问它。那可能看起来像这样:
@if (Session::has('message'))
<div class="alert alert-info">{{ Session::get('message') }}</div>
@endif