diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0699e95..b90a783 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,18 +12,18 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] - php: [7.4,8.0] - laravel: [8.*,9.*] - stability: [prefer-lowest, prefer-stable] + os: [ubuntu-latest] + php: [8.0,8.1,8.2] + laravel: [9.*,10.*] + stability: [prefer-stable] include: - - laravel: 8.* - testbench: ^6.6 - laravel: 9.* testbench: ^7.0 + - laravel: 10.* + testbench: ^8.0 exclude: - - laravel: 9.* - php: 7.4 + - laravel: 10.* + php: 8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/README.md b/README.md index 25db05a..31432ca 100644 --- a/README.md +++ b/README.md @@ -1,214 +1,214 @@ -# Laravel package for manage your URL redirects in database or other sources to get better SEO results - -[![Latest Version on Packagist](https://img.shields.io/packagist/v/sirodiaz/laravel-redirection.svg?style=flat-square)](https://packagist.org/packages/SiroDiaz/laravel-redirection) -[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/SiroDiaz/laravel-redirection/run-tests?label=tests&style=flat-square)](https://github.com/SiroDiaz/laravel-redirection/actions?query=workflow%3Arun-tests+branch%3Amain) -[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/SiroDiaz/laravel-redirection/Check%20&%20fix%20styling?label=code%20style&style=flat-square)](https://github.com/SiroDiaz/laravel-redirection/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) -[![Total Downloads](https://img.shields.io/packagist/dt/SiroDiaz/laravel-redirection.svg?style=flat-square)](https://packagist.org/packages/SiroDiaz/laravel-redirection) - -## Requirements - -You need PHP ^7.4 or higher. It is only tested and was designed for Laravel 8 and 9. -This package will receive updates for future Laravel versions. Previous Laravel versions -are not contemplated so use [Neurony/laravel-redirects](https://github.com/Neurony/laravel-redirects) package for -older Laravel versions. - -## Installation - -You can install the package via composer: - -```bash -composer require SiroDiaz/laravel-redirection -``` - -You can publish and run the migrations with: - -```bash -php artisan vendor:publish --provider="SiroDiaz\Redirection\RedirectionServiceProvider" --tag="redirection-migrations" -php artisan migrate -``` - -You can publish the config file with: -```bash -php artisan vendor:publish --provider="SiroDiaz\Redirection\RedirectionServiceProvider" --tag="redirection-config" -``` - -This is the contents of the published config file: - -```php - [ - 301 => 'Permanent (301)', - 302 => 'Normal (302)', - 307 => 'Temporary (307)', - ], - - /* - |-------------------------------------------------------------------------- - | Default Redirect status code (in case of not defined) - |-------------------------------------------------------------------------- - | - | Status code used by default to redirect from an old URL to a new mapped - | URL. - | - */ - 'default_status_code' => (int)env('REDIRECT_DEFAULT_STATUS', 301), - - /* - |-------------------------------------------------------------------------- - | Case sensitivity - |-------------------------------------------------------------------------- - | - | Whether to match URLs case sensitively or not. - | Default to false because most URLs are not case sensitive. - | - */ - 'case-sensitive' => (bool) env('REDIRECT_CASE_SENSITIVE', false), - - /* - |-------------------------------------------------------------------------- - | Redirect Driver - |-------------------------------------------------------------------------- - | - | Here you may specify the default redirect driver that you want to use. - | The "config" driver is used by default when you want to code faster. - | Consider database driver better for admin panel configuration backed by - | a relational DB. - | - */ - 'driver' => env('REDIRECT_DRIVER', 'config'), - - /* - |-------------------------------------------------------------------------- - | Array containing all available drivers and its implementations and source - |-------------------------------------------------------------------------- - | - | Concrete implementation for the "redirection model". - | To extend or replace this functionality, change the value below with - | your full "redirection model" FQN. - | - | Your class will have to (first option is recommended): - | - extend the "SiroDiaz\Redirection\Models\Redirection" class - | - or at least implement the "SiroDiaz\Redirection\Contracts\RedirectionModelContract" interface. - | - | Regardless of the concrete implementation below, you can still use it like: - | - app('redirection.') OR app('\SiroDiaz\Redirection\Contracts\RedirectionModelContract') - | - or you could even use your own class as a direct implementation. For this - | case you must extend from "SiroDiaz\Redirection\Models\Redirection" model class and - | replace in the published config file 'drivers.database.source'. - | - | - */ - 'drivers' => [ - 'config' => [ - 'driver' => SiroDiaz\Redirection\Drivers\FileRedirector::class, - 'source' => 'redirection.urls', - ], - 'database' => [ - 'driver' => SiroDiaz\Redirection\Drivers\DatabaseRedirector::class, - 'source' => SiroDiaz\Redirection\Models\Redirection::class, - ], - ], - - /* - |-------------------------------------------------------------------------- - | Url list with redirections used for config driver - |-------------------------------------------------------------------------- - | - | You can use urls array of two different ways. The simple one uses the - | default redirect status code ('redirection.default_status_code'). - | Example: - | 'urls' => [ - | '/old/url' => '/new/url', - | '/another/old/url' => '/another/new/url', - | '/url/with?id=123' => '/url/with/123', - | ], - | - | The second way to write redirect urls in your config/redirection.php - | is using associative arrays. You can combine this method with the previous one. - | Look at this example: - | 'urls' => [ - | '/old/url' => ['new_url' => '/new/url', 'status_code' => 302], - | '/another/old/url' => '/another/new/url', - | '/url/with?id=123' => ['new_url' => '/url/with/123'], - | ], - | - */ - 'urls' => [], - -]; - - -``` - -You can change and extend the default `SiroDiaz\Redirection\Models\Redirection` model class. -Image that you want to add some methods or fields. You would need to create a new model class, for example `App\Models\Redirect`. - -Here is a basic example of how to extend the functionality of the default Redirection model. -We want to include support for Laravel BackPack admin panel would be: -```php - [ + 301 => 'Permanent (301)', + 302 => 'Normal (302)', + 307 => 'Temporary (307)', + ], + + /* + |-------------------------------------------------------------------------- + | Default Redirect status code (in case of not defined) + |-------------------------------------------------------------------------- + | + | Status code used by default to redirect from an old URL to a new mapped + | URL. + | + */ + 'default_status_code' => (int)env('REDIRECT_DEFAULT_STATUS', 301), + + /* + |-------------------------------------------------------------------------- + | Case sensitivity + |-------------------------------------------------------------------------- + | + | Whether to match URLs case sensitively or not. + | Default to false because most URLs are not case sensitive. + | + */ + 'case-sensitive' => (bool) env('REDIRECT_CASE_SENSITIVE', false), + + /* + |-------------------------------------------------------------------------- + | Redirect Driver + |-------------------------------------------------------------------------- + | + | Here you may specify the default redirect driver that you want to use. + | The "config" driver is used by default when you want to code faster. + | Consider database driver better for admin panel configuration backed by + | a relational DB. + | + */ + 'driver' => env('REDIRECT_DRIVER', 'config'), + + /* + |-------------------------------------------------------------------------- + | Array containing all available drivers and its implementations and source + |-------------------------------------------------------------------------- + | + | Concrete implementation for the "redirection model". + | To extend or replace this functionality, change the value below with + | your full "redirection model" FQN. + | + | Your class will have to (first option is recommended): + | - extend the "SiroDiaz\Redirection\Models\Redirection" class + | - or at least implement the "SiroDiaz\Redirection\Contracts\RedirectionModelContract" interface. + | + | Regardless of the concrete implementation below, you can still use it like: + | - app('redirection.') OR app('\SiroDiaz\Redirection\Contracts\RedirectionModelContract') + | - or you could even use your own class as a direct implementation. For this + | case you must extend from "SiroDiaz\Redirection\Models\Redirection" model class and + | replace in the published config file 'drivers.database.source'. + | + | + */ + 'drivers' => [ + 'config' => [ + 'driver' => SiroDiaz\Redirection\Drivers\FileRedirector::class, + 'source' => 'redirection.urls', + ], + 'database' => [ + 'driver' => SiroDiaz\Redirection\Drivers\DatabaseRedirector::class, + 'source' => SiroDiaz\Redirection\Models\Redirection::class, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Url list with redirections used for config driver + |-------------------------------------------------------------------------- + | + | You can use urls array of two different ways. The simple one uses the + | default redirect status code ('redirection.default_status_code'). + | Example: + | 'urls' => [ + | '/old/url' => '/new/url', + | '/another/old/url' => '/another/new/url', + | '/url/with?id=123' => '/url/with/123', + | ], + | + | The second way to write redirect urls in your config/redirection.php + | is using associative arrays. You can combine this method with the previous one. + | Look at this example: + | 'urls' => [ + | '/old/url' => ['new_url' => '/new/url', 'status_code' => 302], + | '/another/old/url' => '/another/new/url', + | '/url/with?id=123' => ['new_url' => '/url/with/123'], + | ], + | + */ + 'urls' => [], + +]; + + +``` + +You can change and extend the default `SiroDiaz\Redirection\Models\Redirection` model class. +Image that you want to add some methods or fields. You would need to create a new model class, for example `App\Models\Redirect`. + +Here is a basic example of how to extend the functionality of the default Redirection model. +We want to include support for Laravel BackPack admin panel would be: +```php +