【问题标题】:Why redirect to a specific route doesn't work?为什么重定向到特定路线不起作用?
【发布时间】:2018-05-25 18:09:18
【问题描述】:

这是我的代码:

$msg = 'successfully inserted';
Redirect::route('home')->with($msg);

上面的行在我的脚本的末尾,但没有任何反应。我的意思是insert 查询也可以,但不会重定向到home 页面。注意到我的脚本顶部也有这一行:

use Illuminate\Support\Facades\Redirect;

知道如何让它工作吗?

【问题讨论】:

  • return redirect()->action('HomeController@index')->with($msg);
  • 你的Controller文件和方法是什么?用你的控制器替换 HomeController,用你的方法替换索引。
  • 试试:return redirect('home')->with($msg);
  • @HirenGohel 谢谢,问题是缺少return

标签: php laravel redirect routing


【解决方案1】:

试试看:

return redirect('home')->with($msg);

这将使您返回'home' 路线!

检查documentation

希望对您有所帮助!

【讨论】:

    【解决方案2】:

    试试这样的代码

    redirect()->to('/home')->with($msg);
    

    【讨论】:

      【解决方案3】:

      您可以使用如下消息重定向:

      $msg = 'successfully inserted';
      return redirect()->action('HomeController@index')->with(compact('msg'));
      // Replace HomeController with your Controller and index with your method.
      

      确保您的路线如下所示:

      Route::get('/home', 'HomeController@index');
      

      点击以下链接了解有关 Laravel 重定向的更多信息:

      https://laravel.com/docs/5.5/redirects

      【讨论】:

        猜你喜欢
        • 2016-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 2011-08-21
        • 2021-01-17
        • 1970-01-01
        相关资源
        最近更新 更多