【问题标题】:Redirect to custom tool url in a laravel nova application重定向到 laravel nova 应用程序中的自定义工具 url
【发布时间】:2023-03-07 12:33:01
【问题描述】:
  • Laravel 版本:7
  • Nova 版本:3
  • PHP 版本:7.4
  • 数据库驱动程序和版本:
  • 操作系统和版本:MacOS
  • 浏览器类型和版本:Chrome
  • 复制存储库:https://github.com/###/###

说明:

我在检查中间件中的条件后尝试重定向用户,我尝试使用

return redirect('/admin/paddle-subscription');

但它不起作用,它只是重定向页面并在浏览器 url 中正确显示,但在屏幕上显示 404 错误,看起来 nova 使用 vue.js 它正在创建某种错误。

我一直在阅读 laracast https://laracasts.com/discuss/channels/nova/nova-resource-route-redirect 的一些帖子,我更清楚它需要一种特殊的重定向方式。

我试过了

     return redirect()->action('\Laravel\Nova\Http\Controllers\RouterController@show', ['resource' => '/admin/paddle-subscription']);

而且它不起作用,我应该如何正确重定向?

谢谢

在全新安装 Nova 时重现该问题的详细步骤:

【问题讨论】:

    标签: laravel redirect laravel-nova


    【解决方案1】:

    试试这个:

    添加你的新星动作

    public function handleRequest(\Laravel\Nova\Http\Requests\ActionRequest $request)
    {
        parent::handleRequest($request);
    
        return Action::redirect('/admin/paddle-subscription');
    }
    

    【讨论】:

      【解决方案2】:

      你可以先在后端创建路由,让 Laravel 知道页面存在。使用 Nova 的 RouterController@show 动作作为 Laracast 示例中的路由,并确保将所有 Nova 中间件应用到它。

      app/Providers/NovaServiceProvider.php 中为您的routes() 方法添加自定义路由:

      protected function routes()
      {
          Nova::routes()
              ->withAuthenticationRoutes()
              ->withPasswordResetRoutes()
              ->register();
      
          Route::domain(config('nova.domain', null))
              ->middleware(['web'])
              ->as('nova.')
              ->prefix(Nova::path())
              ->group(function () {
                  Route::get('/admin/paddle-subscription', [\Laravel\Nova\Http\Controllers\RouterController::class, 'show'])
                      ->middleware(config('nova.middleware', []));
              });
      }
      

      在您的中间件中,您现在可以重定向到该路由,页面将正确呈现:

      public function handle(Request $request, Closure $next)
      {
          if ($foo === $bar) {
              return new \Illuminate\Http\RedirectResponse('/admin/paddle-subscription');
          }
      
          return $next($request);
      }
      

      【讨论】:

        猜你喜欢
        • 2019-08-16
        • 2019-06-17
        • 1970-01-01
        • 2019-11-24
        • 1970-01-01
        • 2019-02-02
        • 1970-01-01
        • 1970-01-01
        • 2020-01-12
        相关资源
        最近更新 更多