Added a validator that checks, if a values is empty, if another one is set.
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
|
class CustomValidator extends Validator
|
||||||
|
{
|
||||||
|
public function validateEmpty($attribute, $value)
|
||||||
|
{
|
||||||
|
return !$this->validateRequired($attribute, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateEmptyIf($attribute, $value, $parameters)
|
||||||
|
{
|
||||||
|
$key = $parameters[0];
|
||||||
|
|
||||||
|
if ($this->validateRequired($key, $this->getValue($key))) {
|
||||||
|
return $this->validateEmpty($attribute, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use App\CustomValidator;
|
||||||
|
use Validator;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -13,7 +15,9 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
//
|
Validator::resolver(function ($translator, $data, $rules, $messages) {
|
||||||
|
return new CustomValidator($translator, $data, $rules, $messages);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user