akaunting/app/Http/Requests/Request.php

51 lines
1.2 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\Requests;
use App\Models\Setting\Currency;
2017-09-14 22:21:00 +03:00
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Factory as ValidationFactory;
2017-09-14 22:21:00 +03:00
class Request extends FormRequest
{
public function __construct(ValidationFactory $validation)
{
$validation->extend(
'currency',
function ($attribute, $currency_code, $parameters) {
$currency = false;
$currencies = Currency::enabled()->pluck('name', 'code')->toArray();
if (array_key_exists($currency_code, $currencies)) {
$currency = true;
}
return $currency;
},
trans('validation.custom.invalid_currency', ['attribute' => $currency_code])
);
}
2017-09-14 22:21:00 +03:00
/**
* Set the company id to the request.
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function getValidatorInstance()
{
// Get request data
$data = $this->all();
// Add active company id
$data['company_id'] = session('company_id');
// Reset the request data
$this->getInputSource()->replace($data);
return parent::getValidatorInstance();
}
}