定制 joelshepherd/create-with 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joelshepherd/create-with

Composer 安装命令:

composer require joelshepherd/create-with

包简介

Easily add common unique identity fields to Laravel models.

README 文档

README

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
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.

Default options

  • getSlugField() returns slug
  • getSlugBaseText() returns null
  • getSlugRandomLength() returns 7
<?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.

Default options

  • getIpAddressField() returns ip_address
<?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.

统计信息

  • 总下载量: 5.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固