大家好。我的代码中遇到错误。我正在尝试重定向到另一条路由并用它传递数据。
控制器代码:
return redirect()->route('customer.success', compact('data'));
路线:
Route::get('success-customer', 'CustomerController@showSuccess')->name('customer.success');
叶片:
Your assistant: {{Session::get($data['assistant'])}}
现在我的错误是,它显示了undefined data
的错误,但我使用了compact
函数。 非常感谢您的回答和建议!
在 laravel 5.8 中,您可以执行以下操作:
return redirect('login')->with('data',$data);
在刀片文件中 数据将存储在会话中,而不是存储在变量中。
{{ Session::get('data') }}
你可以使用这个:
return redirect()->route('profile', ['id' => 1]);
若要重定向到任何控制器,请使用此代码
return redirect()->action('DefaultController@index');
如果要使用重定向发送数据,请尝试使用此代码
return Redirect::route('customer.success)->with( ['data' => $data] );
若要读取边栏选项卡中的数据,请使用此边栏选项卡
// in PHP
$id = session()->get( 'data' );
// in Blade
{{ session()->get( 'data' ) }}
查看此处以获取更多信息
try this
return Redirect::route('customer.success')->with(['data'=>$data]);
在刀片中
Session::get('data');