pardalsalcap/hailo-redirections

This is my package hailo-redirections

v0.1.1 2024-02-15 10:49 UTC

This package is auto-updated.

Last update: 2024-11-15 12:46:01 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is an add-on for Hailo that allows you to log 404 errors and create redirections for them.

Installation

You can install the package via composer:

composer require pardalsalcap/hailo-redirections

You can publish and run the migrations with:

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

You can publish the config file with:

php artisan vendor:publish --tag="hailo-redirections-config"

This is the contents of the published config file:

return [
    '404' => true,
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="hailo-redirections-views"

Usage

Add the render method into the app/Exceptions/Handler.php file.

public function render($request, Throwable $e) {
    if ($e instanceof NotFoundHttpException) {
        $http_status = $e->getStatusCode();
        $redirection_repository = new RedirectionRepository();
        $redirection = $redirection_repository->logError(request()->fullUrl(), $http_status);
        if (!empty($redirection->fix)) {
            return redirect($redirection->fix, $redirection->http_status);
        }
    }
    return parent::render($request, $e);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.