2017 © Pedro Peláez
 

library create-with

Easily add common unique identity fields to Laravel models.

image

joelshepherd/create-with

Easily add common unique identity fields to Laravel models.

  • Wednesday, September 13, 2017
  • by joelshepherd
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,947 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 5 Versions
  • 10 % Grown

The README.md

Create With - Laravel Models

A simple package that provides traits to add common indentity fields to Laravel models when they are created., (*1)

This package is designed to work out of the box with just the traits. No other configuration is needed., (*2)

Installation

Dependencies - PHP 7 - Laravel 5.*, (*3)

Composer, (*4)

composer require joelshepherd/create-with

Usage

Simply add the trait to your model that provides your desired field. If the field is not empty and is unique in the database, it will be left unchanged., (*5)

Create with UUID

Adds an unique UUID to the model., (*6)

Default options - getUuidField() returns uuid, (*7)

<?php
use JoelShepherd\CreateWith;

class Example extends Model
{
    use CreateWith\Uuid;
}
<?php

$example = Example::create();
$example->uuid; // 123e4567-e89b-12d3-a456-426655440000

Create with slug

Adds an unique slug to the model. This can optionally be based on a text string (like a title field on the model) and appended with a random slug if required for uniqueness., (*8)

Default options - getSlugField() returns slug - getSlugBaseText() returns null - getSlugRandomLength() returns 7, (*9)

<?php
use JoelShepherd\CreateWith;

class Example extends Model
{
    use CreateWith\Slug;

    // Optionally set the base string to build the slug from
    protected function getSlugBaseText()
    {
        return $this->title;
    }
}
<?php

// Creates a unique slug from the base text
$example = Example::create([
    'title' => 'This is a title'
]);
$example->slug; // this-is-a-title

// Uniqueness is retained even with the same base text
$example2 = Example::create([
    'title' => 'This is a title'
]);
$example2->slug; // this-is-a-title-7iw90lj

Create with IP address

Adds the requester's IP address to the model., (*10)

Default options - getIpAddressField() returns ip_address, (*11)

<?php
use JoelShepherd\CreateWith\WithIpAddress;

class Example extends Model
{
    use CreateWith\IpAddress;
}
<?php

$example = Example::create();
$example->ip_address; // 127.0.0.1

Contributing

Submitting issues and pull requests for bugs, features and feature requests are welcome., (*12)

The Versions

13/09 2017

dev-master

9999999-dev

Easily add common unique identity fields to Laravel models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joel Shepherd

laravel uuid eloquent slug

13/09 2017

0.4.0

0.4.0.0

Easily add common unique identity fields to Laravel models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joel Shepherd

laravel uuid eloquent slug

28/07 2017

0.3.0

0.3.0.0

Easily add common unique identity fields to Laravel models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joel Shepherd

laravel uuid eloquent slug

06/07 2017

0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joel Shepherd

05/07 2017

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joel Shepherd