2014-07-06 08:18:11 -05:00
|
|
|
<?php
|
|
|
|
|
2014-07-15 10:09:59 -05:00
|
|
|
use LaravelBook\Ardent\Ardent;
|
|
|
|
|
2014-11-17 00:33:18 -06:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Preference
|
|
|
|
*
|
2014-11-17 00:33:18 -06:00
|
|
|
* @property integer $id
|
2014-07-15 15:16:29 -05:00
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
2014-11-17 00:33:18 -06:00
|
|
|
* @property integer $user_id
|
|
|
|
* @property string $name
|
|
|
|
* @property string $data
|
|
|
|
* @property-read \User $user
|
2014-11-17 15:32:55 -06:00
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\Preference whereData($value)
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-07-15 10:09:59 -05:00
|
|
|
class Preference extends Ardent
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
|
|
|
public static $rules
|
2014-11-12 15:37:44 -06:00
|
|
|
= ['user_id' => 'required|exists:users,id', 'name' => 'required|between:1,255', 'data' => 'required'];
|
2014-07-06 08:18:11 -05:00
|
|
|
|
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-07-06 08:18:11 -05:00
|
|
|
{
|
2014-11-12 15:37:44 -06:00
|
|
|
return json_decode($value);
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:22:42 -05:00
|
|
|
/**
|
|
|
|
* @param $value
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
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-07-06 08:18:11 -05:00
|
|
|
{
|
2014-11-12 15:37:44 -06:00
|
|
|
return $this->belongsTo('User');
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|