控制器里的代码: return redirect('reviewmessage')->with('message', array('type' => 'success','content'=>'留言成功!您可以查看他人或您之前的留言。')); 路由'reviewmessage'返回视图'reviewmessage', 我在视图中加入 @if (Session::has('message')) {{Session::get('message')['content'] }} @...
Redirect with Error Message(s)If the Controller action failed and you need to redirect with error messages, you have two options.Of course, you can do the same as above. Just name the variable error, something like this:return back()->with('error', 'Something went wrong!');...
return redirect('/error-page'); 上述代码将用户重定向到/error-page页面。 除了简单的重定向之外,Laravel还提供了更多的重定向选项。例如,可以使用with()方法将数据闪存到会话中,以便在重定向后的页面中访问。示例如下: 代码语言:txt 复制 return redirect('/error-page')->with('message', 'An error occurred...
Laravel redirect back: Session::flash('message', "Data saved successfully."); Redirect::back(); The above example will redirect back to previous url with the given message. Now to display the message add the following flash message to display it- Laravel redirect back with message: @if (...
您可以使用执行重定向的中间件来完成此操作。在app/Http/Middleware/Withmessage.php创建中间件,并将其...
Route::post('user/profile',function(){// Update the user's profile...returnredirect('dashboard')->with('status','Profile updated!');}); After the user is redirected, you may display the flashed message from thesession. For example, usingBlade syntax: ...
Route::get('testRedirect', 'UserController@testRedirect'); 示例动作controller: public function testRedirect() { // 以下示例代码放在这个地方 } 1. 简单的重定向 假设我们当前的域名为:http://localhost return redirect('home'); 重定向到 http://localhost/home ...
returnredirect('dashboard')->with('status','Profile updated!'); 此代码会将数据添加到Flash会话闪存数据中,然后你可以在结果 Controller 或视图中使用该数据: @if(session('status')) {{ session('status') }}@endif 用户重定向到新页面之后,你可以从 Session 中取出显示这些一次性信息。
returnredirect('dashboard')->with('status','Profile updated!'); }); After the user is redirected, you may display the flashed message from thesession. For example, usingBlade syntax: @if(session('status')) {{session('status') }} @endif...
Redirecting With Flashed Session Data Redirecting to a new URL andflashing data to the sessionare usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create aRedirectResponseinstanc...