2014-07-05 12:44:26 -05:00
|
|
|
<?php
|
2014-12-20 09:53:32 -06:00
|
|
|
use Illuminate\Database\Eloquent\Model as Eloquent;
|
2014-12-17 13:47:46 -06:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
2014-12-20 09:53:32 -06:00
|
|
|
use Watson\Validating\ValidatingTrait;
|
|
|
|
|
2014-12-13 14:59:02 -06:00
|
|
|
/**
|
|
|
|
* Class Category
|
|
|
|
*/
|
2014-12-17 13:47:46 -06:00
|
|
|
class Category extends Eloquent
|
2014-07-05 12:44:26 -05:00
|
|
|
{
|
2014-12-20 09:53:32 -06:00
|
|
|
use SoftDeletingTrait, ValidatingTrait;
|
|
|
|
protected $fillable = ['name', 'user_id'];
|
|
|
|
protected $rules
|
|
|
|
= [
|
|
|
|
'user_id' => 'exists:users,id|required',
|
|
|
|
'name' => 'required|between:1,100|alphabasic',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove this method in favour of something in the FireflyIII libraries.
|
|
|
|
*
|
|
|
|
* @return Carbon
|
|
|
|
*/
|
|
|
|
public function lastActionDate()
|
|
|
|
{
|
|
|
|
$transaction = $this->transactionjournals()->orderBy('updated_at', 'DESC')->first();
|
|
|
|
if (is_null($transaction)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transaction->date;
|
|
|
|
}
|
2014-12-13 14:59:02 -06:00
|
|
|
|
2014-12-17 13:47:46 -06:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
*/
|
|
|
|
public function transactionjournals()
|
|
|
|
{
|
2014-12-26 15:59:13 -06:00
|
|
|
return $this->belongsToMany('TransactionJournal', 'category_transaction_journal', 'category_id');
|
2014-12-17 13:47:46 -06:00
|
|
|
}
|
2014-11-14 03:17:12 -06:00
|
|
|
|
2014-12-17 13:47:46 -06:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('User');
|
|
|
|
}
|
2015-01-01 23:16:49 -06:00
|
|
|
}
|