PHPackages                             boomdraw/laravel-canonicalizable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. boomdraw/laravel-canonicalizable

ActiveLibrary[Database &amp; ORM](/categories/database)

boomdraw/laravel-canonicalizable
================================

Canonicalizer package for Laravel

v1.3.0(6y ago)1986MITPHPPHP ^7.4

Since Dec 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/boomdraw/laravel-canonicalizable)[ Packagist](https://packagist.org/packages/boomdraw/laravel-canonicalizable)[ Docs](https://github.com/boomdraw/laravel-canonicalizable)[ RSS](/packages/boomdraw-laravel-canonicalizable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Laravel Canonicalizable
=======================

[](#laravel-canonicalizable)

Canonicalizable trait for Eloquent model

[![Build Status](https://camo.githubusercontent.com/a1312477222d7664d29afcac9b8018df346d1f18a980130354253c05d69a3680/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/laravel-canonicalizable)[![StyleCI](https://camo.githubusercontent.com/8bdeec25b4b8be71d7641a4be33633c02eb2cb14b9244209edb86e543f149449/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3232363432323236312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/226422261)[![Code Coverage](https://camo.githubusercontent.com/951ea842479b1f737c917898eb72a23b08afc645c9affc77324159f6fcf0e933/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/laravel-canonicalizable)[![Quality Score](https://camo.githubusercontent.com/5ae606aaa1f2197320872f1ac9500dffc396daa4198e3e4534642598fa7a50dc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/boomdraw/laravel-canonicalizable)[![Latest Version on Packagist](https://camo.githubusercontent.com/10e72f88f1061d83df3bcba1b18219dfbb36cef93f518d4a05ca7478fb63b26b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/laravel-canonicalizable)[![Total Downloads](https://camo.githubusercontent.com/aff9d0cd9e5d7a3647d274ab406832fa8fbd09a869df4ec81805fb06b54d3572/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/laravel-canonicalizable)[![PHP Version](https://camo.githubusercontent.com/ca3bdfc784334c25933414852fd8abf859b9644d4c0441eba4173df5e68b7947/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/laravel-canonicalizable)[![License](https://camo.githubusercontent.com/568031b3e0ca290bde6c459c7163323bd8e2d5621c8ef2264f99fcff4e08b9dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626f6f6d647261772f6c61726176656c2d63616e6f6e6963616c697a61626c653f7374796c653d666c61742d7371756172653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/boomdraw/laravel-canonicalizable)

This package provides a trait that will generate a canonicalized field when saving any Eloquent model.

```
$model = new EloquentModel();
$model->name = 'HeLlO WoRLd';
$model->save();

$model->name_canonical === 'hello world';
```

Installation
------------

[](#installation)

Via Composer

```
$ composer require boomdraw/laravel-canonicalizable
```

### Lumen

[](#lumen)

Uncomment the following line in the bootstrap file:

```
// bootstrap/app.php:
$app->withEloquent();
$app->withFacades();
```

Register `CanonicalizerServiceProvider`

```
// bootstrap/app.php:
$app->register(Boomdraw\Canonicalizer\CanonicalizerServiceProvider::class);
```

Usage
-----

[](#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:

```
