invoiceninja/app/Http/Requests/Payment/StorePaymentRequest.php

74 lines
1.5 KiB
PHP
Raw Normal View History

2019-05-03 17:57:55 +10:00
<?php
2019-05-11 13:32:07 +10:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-05-03 17:57:55 +10:00
namespace App\Http\Requests\Payment;
use App\Http\Requests\Request;
use App\Http\ValidationRules\ValidPayableInvoicesRule;
2019-05-03 17:57:55 +10:00
use App\Models\Payment;
use App\Utils\Traits\MakesHash;
2019-05-03 17:57:55 +10:00
class StorePaymentRequest extends Request
{
use MakesHash;
2019-05-03 17:57:55 +10:00
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
2019-05-03 17:57:55 +10:00
return auth()->user()->can('create', Payment::class);
2019-05-03 17:57:55 +10:00
}
public function rules()
{
$this->sanitize();
$rules = [
'amount' => 'numeric|required',
2019-07-04 14:31:01 +10:00
'payment_date' => 'required',
'client_id' => 'required',
'invoices' => 'required',
'invoices' => new ValidPayableInvoicesRule(),
2019-05-03 17:57:55 +10:00
];
return $rules;
2019-05-03 17:57:55 +10:00
}
public function sanitize()
{
$input = $this->all();
if(isset($input['client_id']))
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
if(isset($input['invoices']))
$input['invoices'] = $this->transformKeys(explode(",", $input['invoices']));
if(is_array($input['invoices']) === false)
$input['invoices'] = null;
2019-05-03 17:57:55 +10:00
$this->replace($input);
2019-05-03 17:57:55 +10:00
return $this->all();
2019-05-03 17:57:55 +10:00
}
2019-05-03 17:57:55 +10:00
}