firefly-iii/app/Models/AccountMeta.php

75 lines
2.2 KiB
PHP
Raw Normal View History

2015-02-05 21:52:16 -06:00
<?php namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
2015-02-05 21:52:16 -06:00
2015-02-11 00:35:10 -06:00
/**
* Class AccountMeta
*
2015-06-03 14:25:11 -05:00
* @codeCoverageIgnore
2015-02-11 00:35:10 -06:00
* @package FireflyIII\Models
2015-06-03 14:25:11 -05:00
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $account_id
* @property string $name
* @property string $data
2015-05-26 05:19:11 -05:00
* @property-read \FireflyIII\Models\Account $account
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereId($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereAccountId($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereName($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereData($value)
2015-02-11 00:35:10 -06:00
*/
2015-02-05 22:04:06 -06:00
class AccountMeta extends Model
{
2015-02-05 21:52:16 -06:00
use ValidatingTrait;
2015-02-23 14:19:16 -06:00
protected $fillable = ['account_id', 'name', 'data'];
protected $rules
2015-03-29 14:27:51 -05:00
= [
'account_id' => 'required|exists:accounts,id',
'name' => 'required|between:1,100',
'data' => 'required'
];
2015-06-03 14:25:11 -05:00
protected $table = 'account_meta';
2015-02-11 00:35:10 -06:00
/**
*
2015-02-11 00:35:10 -06:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2015-02-05 22:04:06 -06:00
public function account()
{
2015-02-05 22:35:00 -06:00
return $this->belongsTo('FireflyIII\Models\Account');
2015-02-05 22:04:06 -06:00
}
2015-02-11 00:35:10 -06:00
/**
* @param $value
*
* @return mixed
*/
2015-02-05 22:04:06 -06:00
public function getDataAttribute($value)
{
return json_decode($value);
}
2015-02-11 00:35:10 -06:00
/**
* @return array
*/
2015-02-07 05:15:53 -06:00
public function getDates()
{
return ['created_at', 'updated_at'];
}
2015-02-05 21:52:16 -06:00
2015-02-11 00:35:10 -06:00
/**
* @param $value
*/
2015-02-07 06:15:40 -06:00
public function setDataAttribute($value)
{
$this->attributes['data'] = json_encode($value);
}
2015-02-05 21:52:16 -06:00
}