Download the PHP package boomdraw/laravel-canonicalizable without Composer
On this page you can find all versions of the php package boomdraw/laravel-canonicalizable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download boomdraw/laravel-canonicalizable
More information about boomdraw/laravel-canonicalizable
Files in boomdraw/laravel-canonicalizable
Package laravel-canonicalizable
Short Description Canonicalizer package for Laravel
License MIT
Homepage https://github.com/boomdraw/laravel-canonicalizable
Informations about the package laravel-canonicalizable
Laravel Canonicalizable
Canonicalizable trait for Eloquent model
This package provides a trait that will generate a canonicalized field when saving any Eloquent model.
Installation
Via Composer
Lumen
Uncomment the following line in the bootstrap file:
Register CanonicalizerServiceProvider
Usage
Your Eloquent models should use the Boomdraw\Canonicalizable\HasCanonical
trait,
the Boomdraw\Canonicalizable\CanonicalFieldsCollection
and the Boomdraw\Canonicalizable\CanonicalField
classes.
The trait contains an abstract method getCanonicalFields()
that you must implement yourself.
Your models' migrations should have a field to save the canonicalized value.
Here's an example of how to implement the trait:
With its migration:
By default, the package will generate non-unique canonicalized fields. You can disallow duplicates by calling
disallowDuplicate()
.
The canonicalized uniqueness will be checked even if it has been set manually and doNotGenerateOnUpdate
or
doNotGenerateOnCreate
are used.
The canonicalized will be made unique by appending -
and a number.
To add a custom separator between canonicalized and a number, pass it as an arg to disallowDuplicate()
.
You can call a custom canonicalization method by providing the field type.
The trait will look for method canonicalizeOther(string $string)
in the model and other(string $string)
method in the
boomdraw/canonicalizer
and it's
macroses.
The canonicalization method also can be provided by using the callback
function.
The type will be ignored if the callback
function provided.
You can pass additional arguments to the type based method by providing an array of arguments in the type method.
You can also override the generated canonical just by setting it to another value than the generated canonical.
To force the canonicalization when a canonical is set manually use forceCanonicalization()
method.
If you don't want to create the canonical when the model is initially created you can set use the doNotGenerateOnCreate()
function.
If you don't want to create the canonical when the model is initially created you can set use the doNotGenerateOnUpdate()
function.
This can be helpful for creating fields that don't change until you explicitly want it to.
If you want to explicitly update the canonical on the model you can call canonicalize(string $fieldName)
on your model
at any time to regenerate the canonical according to your other options.
Don't forget to save()
the model to persist the update to your database.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
You can run the tests with:
Contributing
Please see CONTRIBUTING for details and a todo list.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
License
All versions of laravel-canonicalizable with dependencies
boomdraw/canonicalizer Version ^2
illuminate/database Version ^6.0
illuminate/support Version ^6.0