outl1ne / nova-redirects

Redirect manager for Laravel Nova
MIT License
11 stars 4 forks source link

Not Working Laravel 7x & Nova 3x #2

Open DerekBuntin opened 4 years ago

DerekBuntin commented 4 years ago

I tried creating a redirect, which saved ok with exception to the type now updating correctly but when I try and visit a page that I added a redirect for it doesn't redirect, not sure what exactly this package is supposed to do but it doesn't seem to work.

sicbe commented 4 years ago

I used the tool to create my redirects.

I then made a "Redirect" middleware and used the Model provided by the tool to chech for a redirect and redirect the user.

`<?php

namespace App\Http\Middleware;

use Closure; use OptimistDigital\NovaRedirects\Models\Redirect as RedirectModel;

class Redirect { /**

Assign it in the HTTP Kernel.

protected $middleware = [ //... \App\Http\Middleware\Redirect::class, ];

Seems to work.

DerekBuntin commented 4 years ago

I used the tool to create my redirects.

I then made a "Redirect" middleware and used the Model provided by the tool to chech for a redirect and redirect the user.

`<?php

namespace App\Http\Middleware;

use Closure; use OptimistDigital\NovaRedirects\Models\Redirect as RedirectModel;

class Redirect { /**

  • Handle an incoming request.
  • @param \Illuminate\Http\Request $request
  • @param \Closure $next
  • @return mixed */ public function handle($request, Closure $next) { $redirect = RedirectModel::whereFromUrl($request->path())->first();
    if ($redirect) {
        return redirect($redirect->to_url);
    }

    return $next($request);
}

}`

Assign it in the HTTP Kernel.

protected $middleware = [ //... \App\Http\Middleware\Redirect::class, ];

Seems to work.

I expected this to be part of the package rather than having to create my own, which could easily be done without the package.

techguydev commented 4 years ago

Hi all, why is this package needed in nova?, I am trying to do a simple redirect inside a middleware I have created for nova and it is not redirectling correctly, can someone tell me why?

    public function handle($request, Closure $next)
    {        

         if ($request->path() === 'admin/dashboards/main')     
        {

        // This user is not a paying customer...
             return $next($request);
        }

      return redirect('/admin/dashboards/main');
    }
assertchris commented 3 years ago

I have submitted a PR to introduce a middleware for this: https://github.com/optimistdigital/nova-redirects/pull/5