firefly-iii/app/models/Preference.php

42 lines
867 B
PHP
Raw Normal View History

<?php
2014-12-31 00:43:33 -06:00
use Illuminate\Database\Eloquent\Model as Eloquent;
2014-12-06 05:12:55 -06:00
use Watson\Validating\ValidatingTrait;
2014-12-31 00:43:33 -06:00
2014-12-13 14:59:02 -06:00
/**
* Class Preference
*/
2014-12-06 05:12:55 -06:00
class Preference extends Eloquent
{
2014-12-06 05:12:55 -06:00
use ValidatingTrait;
2014-12-31 00:43:33 -06:00
protected $fillable = ['name', 'data', 'user_id'];
protected $rules
= ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'data' => 'required'];
2014-08-10 11:22:42 -05:00
/**
2014-11-12 15:37:44 -06:00
* @param $value
*
* @return mixed
2014-08-10 11:22:42 -05:00
*/
2014-11-12 15:37:44 -06:00
public function getDataAttribute($value)
{
2014-11-12 15:37:44 -06:00
return json_decode($value);
}
2014-08-10 11:22:42 -05:00
/**
* @param $value
*/
public function setDataAttribute($value)
{
$this->attributes['data'] = json_encode($value);
}
2014-08-10 11:22:42 -05:00
/**
2014-11-12 15:37:44 -06:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
2014-08-10 11:22:42 -05:00
*/
2014-11-12 15:37:44 -06:00
public function user()
{
2014-11-12 15:37:44 -06:00
return $this->belongsTo('User');
}
2015-01-01 23:16:49 -06:00
}