firefly-iii/app/models/Account.php

109 lines
3.0 KiB
PHP
Raw Normal View History

<?php
use Carbon\Carbon;
use LaravelBook\Ardent\Ardent as Ardent;
2014-08-30 07:26:33 -05:00
use LaravelBook\Ardent\Builder;
2014-07-15 15:16:29 -05:00
/**
* Account
*
2014-11-22 01:17:37 -06:00
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $user_id
* @property integer $account_type_id
* @property string $name
* @property boolean $active
* @property-read \AccountType $accountType
2014-07-15 15:16:29 -05:00
* @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions
2014-11-22 01:17:37 -06:00
* @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\Account whereId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereAccountTypeId($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereName($value)
* @method static \Illuminate\Database\Query\Builder|\Account whereActive($value)
* @method static \Account accountTypeIn($types)
2014-07-15 15:16:29 -05:00
*/
class Account extends Ardent
{
/**
* Validation rules.
*
* @var array
*/
public static $rules
2014-11-17 13:45:55 -06:00
= [
2014-11-25 13:44:46 -06:00
'name' => ['required', 'between:1,100'],
2014-11-17 13:45:55 -06:00
'user_id' => 'required|exists:users,id',
'account_type_id' => 'required|exists:account_types,id',
'active' => 'required|boolean'
2014-07-09 06:19:30 -05:00
];
2014-11-10 11:38:58 -06:00
protected $fillable = ['name', 'user_id', 'account_type_id', 'active'];
/**
2014-11-12 15:37:44 -06:00
* Account type.
*
2014-11-12 15:37:44 -06:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2014-11-12 15:37:44 -06:00
public function accountType()
{
2014-11-12 15:37:44 -06:00
return $this->belongsTo('AccountType');
}
2014-11-17 00:33:18 -06:00
/**
* Transactions.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('Transaction');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function piggybanks()
{
return $this->hasMany('Piggybank');
}
2014-08-10 11:22:42 -05:00
/**
2014-11-21 04:11:52 -06:00
*
2014-11-10 11:38:58 -06:00
* @param Builder $query
* @param array $types
*/
public function scopeAccountTypeIn(Builder $query, array $types)
{
if (is_null($this->joinedAccountTypes)) {
$query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id');
2014-08-30 07:26:33 -05:00
$this->joinedAccountTypes = true;
}
2014-11-10 11:38:58 -06:00
$query->whereIn('account_types.type', $types);
2014-08-30 07:26:33 -05:00
}
2014-11-22 01:21:10 -06:00
/**
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
2014-11-21 04:11:52 -06:00
public function transactionjournals()
{
return $this->hasManyThrough('TransactionJournal', 'Transaction');
}
2014-11-12 15:37:44 -06:00
/**
* User
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('User');
}
2014-08-30 07:26:33 -05:00
}