larapack/attribute-slugging

Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.
2,024 5
Install
composer require larapack/attribute-slugging
Latest Version:v1.0.3
License:MIT
Last Updated:Dec 17, 2015
Links: GitHub  ·  Packagist
Maintainer: marktopper

attribute-slugging

Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.

Installing

Install using Composer composer require larapack/attribute-slugging 1.*.

Usage

First add the trait Sluggable to your Eloquent Model.

<?php

namespace App;

use Larapack\AttributeSlugging\Sluggable;

class User
{
  use Sluggable;
  
  /**
   * @var array List of attribute names which should be slugged
   */ 
  protected $slug = [
    'username_slug' => 'username', // set the attribute names you which to slug and from what attribute it should be generated from
  ];
  
  //...
}

Test:

// we make two user objects
$userA = new App\User;
$userB = new App\User;
// then we set both username's to "Mark"
$userA->username = "Mark";
$userB->username = "Mark";
// save both objects
$userA->save();
$userB->save();
// now the unique slugs have been set
echo $userA->username_slug; // outputs "mark"
echo $userB->username_slug; // outputs "mark-2"

Related Packages

larapack/attribute-encryption

Allows you to define what attributes in your eloquent model which should be encr...

1,936 3
larapack/attribute-hashing

Allows you to define what attributes in your Eloquent Model which should be hash...

1,236 2
larapack/command-validation

Enable a method for Artisan Commands to validate the output of methods like `ask...

4,261 12
larapack/attribute-manipulation

Allows multiple traits to manipulate with the attributes of an Eloquent Model.

3,187 4
larapack/command-verification

Makes Artisan Commands prompt the console if it should continue.

15 1