PHPackages                             pardalsalcap/linter-redirections - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pardalsalcap/linter-redirections

ActiveLibrary

pardalsalcap/linter-redirections
================================

Add on to manage 404 and redirections into linter and filament

v5.0.0(2mo ago)040MITPHPPHP ^8.2CI failing

Since Dec 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/pardalsalcap/linter-redirections)[ Packagist](https://packagist.org/packages/pardalsalcap/linter-redirections)[ Docs](https://github.com/pardalsalcap/linter-redirections)[ RSS](/packages/pardalsalcap-linter-redirections/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (26)Versions (7)Used By (0)

Add on to manage 404 and redirections into linter and filament
==============================================================

[](#add-on-to-manage-404-and-redirections-into-linter-and-filament)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d8609f9ba646fc8f7826238dde68e0b0dc152fa7bd4d31a56456e434c117e97c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70617264616c73616c6361702f6c696e7465722d7265646972656374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pardalsalcap/linter-redirections)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4bcf1f05cb3a7fa22cf4bb6bc9b9098dbb2b0471f48e3408e5d10a50c8e7601b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70617264616c73616c6361702f6c696e7465722d7265646972656374696f6e732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/pardalsalcap/linter-redirections/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d7be009064495c10e6a69660263853fbe1787b18997b017c0300fdefd71804c7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70617264616c73616c6361702f6c696e7465722d7265646972656374696f6e732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/pardalsalcap/linter-redirections/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/52d9925fc2de7d08aeda147725a279a3c8bff502e0647a4fb851d079d626a57c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70617264616c73616c6361702f6c696e7465722d7265646972656374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pardalsalcap/linter-redirections)

`main` targets Filament 5.

`v3.0.0` is the last release compatible with Filament 3.

This package is an add-on for the Linter panel to manage 404s and redirections. It includes a Filament resource and two dashboard widgets.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require pardalsalcap/linter-redirections
```

If you need Filament 3 compatibility, install `v3.0.0`.

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="linter-redirections-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="linter-redirections-config"
```

This is the contents of the published config file:

```
return [
];
```

Usage
-----

[](#usage)

To register the 404 or any Exception you like to monitor you can add the following code to your `app/Exceptions/Handler.php` file:

```
use Pardalsalcap\LinterRedirections\Repositories\RedirectionRepository;

public function render($request, Throwable $e) {
    switch(class_basename($e)){
        case 'NotFoundHttpException':
            $http_status = $e->getStatusCode();

            $redirection_repository = new RedirectionRepository();
            $redirection = $redirection_repository->check(request()->fullUrl());
            if ($redirection) {
                return redirect($redirection->fix, $redirection->http_status);
            }

            if ($http_status == "404")
            {
                $redirection_repository->logError(request()->fullUrl(), $http_status);
            }
        break;
    }
    return parent::render($request, $e);
}
```

In Laravel 11 you can modify the /bootstrap/app.php file to add the following code:

```
    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->render(function (NotFoundHttpException $e, Request $request) {
            $http_status = $e->getStatusCode();

            $redirection_repository = new RedirectionRepository();
            $redirection = $redirection_repository->check(request()->fullUrl());
            if ($redirection) {
                return redirect($redirection->fix, $redirection->http_status);
            }

            if ($http_status == "404")
            {
                $redirection_repository->logError(request()->fullUrl(), $http_status);
            }
            //return view('errors.404');
        });
    })
```

If you want to log any other exception you can add it to the switch case.

Filament Resource
-----------------

[](#filament-resource)

To manage redirections from your Filament panel, create an app resource that extends the package resource:

```
