定制 igaster/laravel-model-options 二次开发

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

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

igaster/laravel-model-options

Composer 安装命令:

composer require igaster/laravel-model-options

包简介

Store an Options array in a JSON column. Get/Set values as if they were seperate keys in the Database

README 文档

README

Laravel License Build Status Downloads

A simple Trait to store an Options array in a JSON column. Get/Set values as if they were seperate keys in the Database

Installation

Edit your project's composer.json file to require:

"require": {
    "igaster/laravel-model-options": "~1.0"
}

and install with composer update

How to use

  1. Define a JSON key with name 'options' in your migration file:
$table->json('options')->nullable();

note that older versions of mySql don't support the json type. In that case you can safely fallback to a string type:

$table->string('options')->nullable();
  1. Use the Trait in the coresponding model:

     use \igaster\modelOptions\modelOptions;
    
  2. Define the valid option keys in model:

     protected $validOptions=[
         'option_1',
         'option_2',
     ];
    

Usage:

Access option key as if they were columns in your Database. eg:

    $model->option_1 = 'value1';

Handle Conflicts:

This Trait makes use of the __get() and __set() magic methods to perform its ... well... magic! However if you want to implement these functions in your model or another trait then php will complain about conflicts. To overcome this problem you have to hide the Traits methods when you import it:

use igaster\modelOptions\modelOptions {
    __get as private; 
    __set as private; 
}

and call them manually from your __get() / __set() mehods:

//--- copy these in your model if you need to implement __get() __set() methods

public function __get($key) {
    // Handle modelOptions keys
    $result=$this->modelOptions_get($key);
    if ($this->modelOptions_handled)
        return $result;
    
    //your code goes here
    
    return parent::__get($key);
}

public function __set($key, $value) {
    // Handle modelOptions keys
    $this->modelOptions_set($key, $value);
    if ($this->modelOptions_handled)
        return;

    //your code goes here

    parent::__set($key, $value);
}     

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固