orange-shadow/properties

从Laravel的任何模型中获取类型化属性

0.0.1 2016-07-04 21:33 UTC

This package is auto-updated.

Last update: 2024-09-09 14:02:55 UTC


README

RU] #为任意模型添加具有验证的任意属性包

  • 步骤 1: 在 app/config/app.php 中连接服务提供者 'orangeShadow\properties\PropertiesServiceProvider'

  • 步骤 2: 导入迁移: php artisan vendor:publish, php artisan migrate

  • 步骤 3: 创建(假设我们有一个名为Page的模型)

$property = orangeShadow\CustomModelProperties\Model\Property::create(
				[
					"model"=>"Page",
					"code"=>"VIEWS",
					"title"=>"Кол-во просмотров",
					"description"=>"Счетчик просмотра страницы",
					"type"=>"numeric",
					"sort"=>"1",
					"multiple"=>false,
					"required"=>true
				]
		);
  • 步骤 4: 向模型Page添加Trait use orangeShadow\CustomModelProperties\TraitProperty;

  • 步骤 5: 可以通过代码设置属性或获取它

$page = App\Page::find(1);
//Задать значение свойства по коду 
$page->setPropertyValueByCode('VIEWS',1);
//Получить значение свойства по коду
$page->getPropertyValueByCode('VIEWS');

##TraitProperty的辅助方法

获取当前模型的所有属性列表 getProperties()

获取当前模型的所有属性值列表 getPropertiesValue

如果继承自 orangeShadow\CustomModelProperties\Http\Requests

public function rules()
{
  $rules = parent::relus();
  $rules+=[свои правила];
  return $rules;
}

则获取 properties.code 参数的验证