Download the PHP package vlados/laravel-unique-urls without Composer
On this page you can find all versions of the php package vlados/laravel-unique-urls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vlados/laravel-unique-urls
More information about vlados/laravel-unique-urls
Files in vlados/laravel-unique-urls
Package laravel-unique-urls
Short Description A package for using and generating unique urls for each Eloquent model in Laravel
License MIT
Homepage https://github.com/vlados/laravel-unique-urls
Informations about the package laravel-unique-urls
Unique Urls for Laravel
Generate unique urls for blogs, ecommerce and platforms without prefix. Laravel
- Installation
- Usage
- Configuration
- Routes
- Prepare your model
- Disable auto creating urls
- Livewire
- Contributing
Goals:
- When create or update a model to generate a unique url based on urlStrategy() function inside each model
- Possibility to have different urls for the different languages (not only a prefix in the beginning)
- If the url exists to create a new url with suffix _1, _2, etc.
- If we update the model to create a redirect from the old to the new url
- If there is a multiple redirects to redirect only to the last one
- Possibility to have an url depending on relations (category-name/product-name)
Installation
You can install the package via composer:
You can publish and run the migrations with:
Usage
Configuration
You can publish the config file with:
There will create unique-urls.php
with:
Prepare your model
In your Model add these methods:
The method for handling the request:
Routes
And last, add this line at the end of your routes/web.php
Batch import
If for example you have category tree and you need to import all the data before creating the urls, you can disable the automatic generation of the url on model creation
To disable automatically generating the urls on create or update overwrite the method isAutoGenerateUrls
in the model:
and call generateUrl()
later like this:
or if you want to disable it on the go, use
Livewire
To use Livewire full-page component to handle the request, first set in urlHandler()
function in your model:
Example livewire component:
API
Methods | Description | Parameters |
---|---|---|
generateUrl() | Generate manually the URL | |
urlStrategy | The strategy for creating the URL for the model | $language, $locale |
isAutoGenerateUrls() | Disable generating urls on creation, globally for the model | |
disableGeneratingUrlsOnCreate() | Disable generating urls on creation | |
Properties | ||
relative_url | The url path, relative to the site url | |
absolute_url | The absolute url, including the domain | |
Relations | ||
urls() | All the active urls, related to the current model |
Commands
urls:generate
This command generates unique URLs for the specified model or all models in the application that implement the HasUniqueUrls
trait.
Usage:
urls:doctor
This command checks if all models in the application have implemented the HasUniqueUrls trait and the required functions correctly.
Usage:
Checks
- Check if all the methods are implemented with the right parameters
- Check if the urlHandler is returning the correct controller and method
- Check if urlStrategy is generating unique urls for all the languages
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Semantic Commit Messages
See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
More Examples:
feat
: (new feature for the user, not a new feature for build script)fix
: (bug fix for the user, not a fix to a build script)docs
: (changes to the documentation)style
: (formatting, missing semi colons, etc; no production code change)refactor
: (refactoring production code, eg. renaming a variable)test
: (adding missing tests, refactoring tests; no production code change)chore
: (updating grunt tasks etc; no production code change)
References:
- https://www.conventionalcommits.org/
- https://seesparkbox.com/foundry/semantic_commit_messages
- http://karma-runner.github.io/1.0/dev/git-commit-msg.html
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Vladislav Stoitsov
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-unique-urls with dependencies
illuminate/contracts Version ^9.0|^10.0|^11.0
spatie/laravel-model-info Version ^1.4|^2.0
spatie/laravel-package-tools Version ^1.9.2|^2.0
spatie/laravel-translatable Version ^6.0|^7.0