firefly-iii/app/Http/Requests/BillFormRequest.php

74 lines
2.3 KiB
PHP
Raw Normal View History

2015-02-25 08:19:14 -06:00
<?php
namespace FireflyIII\Http\Requests;
use Auth;
2015-03-29 04:51:26 -05:00
use Carbon\Carbon;
2015-02-25 08:19:14 -06:00
use Input;
/**
* Class BillFormRequest
*
2015-05-10 01:08:07 -05:00
* @codeCoverageIgnore
2015-02-25 08:19:14 -06:00
* @package FireflyIII\Http\Requests
*/
class BillFormRequest extends Request
{
/**
* @return bool
*/
public function authorize()
{
// Only allow logged in users
return Auth::check();
}
2015-03-29 04:51:26 -05:00
/**
* @return array
*/
public function getBillData()
{
return [
'name' => $this->get('name'),
'match' => $this->get('match'),
'amount_min' => floatval($this->get('amount_min')),
'amount_currency_id' => floatval($this->get('amount_currency_id')),
'amount_max' => floatval($this->get('amount_max')),
'date' => new Carbon($this->get('date')),
'user' => Auth::user()->id,
'repeat_freq' => $this->get('repeat_freq'),
'skip' => intval($this->get('skip')),
'automatch' => intval($this->get('automatch')) === 1,
'active' => intval($this->get('active')) === 1,
];
}
2015-02-25 08:19:14 -06:00
/**
* @return array
*/
public function rules()
{
2015-03-31 07:16:25 -05:00
$nameRule = 'required|between:1,255|uniqueObjectForUser:bills,name,name_encrypted';
$matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match,match_encrypted';
2015-03-01 00:50:26 -06:00
if (intval(Input::get('id')) > 0) {
2015-03-31 07:16:25 -05:00
$nameRule .= ',' . intval(Input::get('id'));
$matchRule .= ',' . intval(Input::get('id'));
2015-02-25 08:19:14 -06:00
}
$rules = [
'name' => $nameRule,
2015-03-31 07:16:25 -05:00
'match' => $matchRule,
2015-02-25 08:19:14 -06:00
'amount_min' => 'required|numeric|min:0.01',
'amount_max' => 'required|numeric|min:0.01',
'amount_currency_id' => 'required|exists:transaction_currencies,id',
'date' => 'required|date',
'repeat_freq' => 'required|in:weekly,monthly,quarterly,half-year,yearly',
'skip' => 'required|between:0,31',
'automatch' => 'in:1',
'active' => 'in:1',
];
return $rules;
}
2015-03-29 01:14:32 -05:00
}