承接 ponich/eloquent-traits 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ponich/eloquent-traits

Composer 安装命令:

composer require ponich/eloquent-traits

包简介

Traits for laravel eloquent models

README 文档

README

Build Status License Latest Stable Version Total Downloads

This package adds the ability to use traits in you Laravel Eloquent Models

Traits list

Installation

This package can be used in Laravel 5.5 or higher.

composer require ponich/eloquent-traits

You can publish the migration with:

php artisan vendor:publish --provider="Ponich\Eloquent\Traits\ServiceProvider" --tag="migrations"

After the migration has been published you can create tables by running the migrations:

php artisan migrate

Traits

Virtual Attributes

Adds the ability to create virtual attributes in your model.

Use trait: \Ponich\Eloquent\Traits\VirtualAttribute

Example:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use \Ponich\Eloquent\Traits\VirtualAttribute;

    protected $table = 'posts';

    protected $guarded = ['id'];

    public $virtalAttributes = ['tags', 'og_tags'];
}

In the property of the class $virtalAttributes list all valid virtual attributes.

$post = Post::firstOrFail(1);

$post->tags = ['tag1', 'tag2', 'tag3'];
$post->save();

$post->refresh();

var_dump($post->tags); 
/**
    array(3) {
      [0]=>
      string(4) "tag1"
      [1]=>
      string(4) "tag2"
      [2]=>
      string(4) "tag3"
    }
*/

Attachments

Allows links files to models

Use trait: \Ponich\Eloquent\Traits\HasAttachment

Example:

Model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use \Ponich\Eloquent\Traits\HasAttachment;

    protected $table = 'posts';

    protected $guarded = ['id'];
}

Add attachment :

$post = Post::findOrFail(1);

// by path
$post->attach('/path/to/file');

// by request
$post->attach(
    $request->file('photo')
);

统计信息

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

GitHub 信息

  • Stars: 18
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固