Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joelshepherd/create-with
Easily add common unique identity fields to Laravel models.
https://github.com/joelshepherd/create-with
laravel laravel-model slug trait uuid
Last synced: about 1 month ago
JSON representation
Easily add common unique identity fields to Laravel models.
- Host: GitHub
- URL: https://github.com/joelshepherd/create-with
- Owner: joelshepherd
- License: mit
- Created: 2017-07-05T00:23:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T13:13:30.000Z (almost 7 years ago)
- Last Synced: 2024-04-26T03:00:55.729Z (8 months ago)
- Topics: laravel, laravel-model, slug, trait, uuid
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Create With - Laravel Models
A simple package that provides traits to add common indentity fields to Laravel
models when they are created.This package is designed to work out of the box with just the traits. No other
configuration is needed.## Installation
**Dependencies**
- PHP 7
- Laravel 5.***Composer**
```
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.### Create with UUID
Adds an unique UUID to the model.**Default options**
- `getUuidField()` returns `uuid````php
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.**Default options**
- `getSlugField()` returns `slug`
- `getSlugBaseText()` returns `null`
- `getSlugRandomLength()` returns `7````php
title;
}
}
``````php
'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.**Default options**
- `getIpAddressField()` returns `ip_address````php
ip_address; // 127.0.0.1
```## Contributing
Submitting issues and pull requests for bugs, features and feature requests are welcome.