Download the PHP package ruthgeridema/laravel-url-rewrites without Composer
On this page you can find all versions of the php package ruthgeridema/laravel-url-rewrites. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ruthgeridema/laravel-url-rewrites
More information about ruthgeridema/laravel-url-rewrites
Files in ruthgeridema/laravel-url-rewrites
Package laravel-url-rewrites
Short Description Easy URL rewrites in your Laravel application
License MIT
Homepage https://github.com/ruthgeridema/laravel-url-rewrites
Informations about the package laravel-url-rewrites
Easily add URL rewrites to a Laravel app
Very easy to use URL rewrite package. Follow the instructions and you're good to go!
You can find an example project on my Github: view example project
This example project features the following:
- Eloquent observers to add URL rewrites automatically
- Usage of the trait
- Some use cases
Requirements
This package requires Laravel 5.8 or higher, PHP 7.2 or higher and a database that supports json fields and functions such as MySQL 5.7 or higher.
Installation
You can install the package via composer:
The package will automatically register itself.
Register the routes the feeds will be displayed on using the rewrites
-macro.
You need to place it at the bottom of your routes file.
You can publish the migration with:
After the migration has been published you can create the url_rewrites
table by running the migration:
You can optionally publish the config file with:
This is the contents of the published config file:
Laravel Nova
Using Laravel Nova? You can publish the Nova class to App/Nova with the following command
In the near future I will publish a Laravel Nova package with features like reindexing the URL rewrites.
Usage
Forward request
Let's say you've got a controller route 'product/{id}' and you have a product 'Apple Airpods' with id=5.
When you visit 'apple-airpods' this package will forward the request to the controller but keeps the clean url.
The following code adds this to the database:
Use named routes
You must specify the types in the config.
To regenerate the target path you can use
To automatically add the URL attribute to an Eloquent model, you have to add the HasUrlRewrite trait to an Eloquent model.
You also need to add the urlRewriteType and optionally add 'url' to the appends array.
Once this is done you can simply call Model::find(1)->url
to get the url of the model.
Redirect
301 redirect
302 redirect
Other functions
Testing
- Copy
.env.example
to.env
and fill in your database credentials. - Run
composer test
.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Ruthger Idema
- All Contributors
Special thanks for Spatie for their guidelines and their packages as an inspiration
License
The MIT License (MIT). Please see License File for more information.