GithubHelp home page GithubHelp logo

matteoggl / linnaeus Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 0.0 21 KB

A package to create readable, random slugs for Eloquent models from animal names and adjectives.

License: MIT License

PHP 100.00%
laravel eloquent php slug

linnaeus's Introduction

Linnaeus

GitHub Packagist Downloads

A package to create readable, random slugs for Eloquent models from animal names and adjectives.

Installation

Just require the package through composer:

composer require matteoggl/linnaeus

Usage

Add the HasSlug trait on your Eloquent model and insert a column on it's table named slug, of type string with a unique modifier.

$table->string('slug')->unique();

By default, a new unique string taken from a combination of 900~ adjectives, 100+ colors and 250~ animals is assigned to the model when created with the following structure: adjective-adjective-animal.

When updated, the slug will not be changed and if soft-deletable, the model's slug will be considered used.

The slugs are used with Laravel's implicit route model binding. For example, this code:

Route::get('/users/{user}', function (App\User $user) {
    return $user->email;
});

will use Linnaeus' slugs (e.g. /users/moldy-encouraging-turtle).

Configuration

To publish the configuration file, run the following command:

php artisan vendor:publish --provider="MatteoGgl\Linnaeus\LinnaeusServiceProvider" --tag="config"

The linnaeus.php configuration file will appear in your config/ directory.

Per-model configuration

Some options can be overridden by updating them inside the model constructor, using a fluent API; here's an example using all the available ones:

public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->linnaeus = LinnaeusOptions::create()
            ->withKey('linnaeus_slug')
            ->withStructure(['color', 'animal'])
            ->withSeparator('_')
            ->generatesOnUpdate()
            ->withInvalidAnimals(['aardvark'])
            ->withInvalidAdjectives(['zany'])
            ->withInvalidColors(['blue']);
    }

FAQ

Q: What's up with the name?

A: Take a look at Carl Linnaeus on Wikipedia

Q: Can this package do feature?

A: I created this package out of a need for a personal project. If you have some suggestions feel free to open an issue or a PR! Also, this package is heavily inspired from spatie/laravel-sluggable; maybe the features you are looking for are there.

linnaeus's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.