1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Http/Requests/Statements/CreateStatementRequest.php
2021-09-14 13:55:41 +02:00

52 lines
1.2 KiB
PHP

<?php
namespace App\Http\Requests\Statements;
use App\Http\Requests\Request;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
class CreateStatementRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return auth()->user()->isAdmin();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'start_date' => 'required|date_format:Y-m-d',
'end_date' => 'required|date_format:Y-m-d',
'client_id' => 'bail|required|exists:clients,id,company_id,' . auth()->user()->company()->id,
'show_payments_table' => 'boolean',
'show_aging_table' => 'boolean',
];
}
protected function prepareForValidation()
{
$input = $this->all();
$input = $this->decodePrimaryKeys($input);
$this->replace($input);
}
public function client(): ?Client
{
return Client::where('id', $this->client_id)->first();
}
}