Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Not Working Laravel 7x & Nova 3x #2

Open
DerekBuntin opened this issue Jun 1, 2020 · 4 comments
Open

Not Working Laravel 7x & Nova 3x #2

DerekBuntin opened this issue Jun 1, 2020 · 4 comments

Comments

@DerekBuntin
Copy link

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
Copy link

sicbe commented Jun 13, 2020

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.

@DerekBuntin
Copy link
Author

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
Copy link

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
Copy link

I have submitted a PR to introduce a middleware for this: #5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants