close #398 Added: Add custom validation type : currency

This commit is contained in:
cuneytsenturk
2018-06-27 19:28:56 +03:00
parent e7c7a472c1
commit 896bc1f2b9
11 changed files with 32 additions and 9 deletions

View File

@@ -2,11 +2,33 @@
namespace App\Http\Requests;
use App\Models\Setting\Currency;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Factory as ValidationFactory;
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])
);
}
/**
* Set the company id to the request.
*