Sí es posible, pero no con los métodos de validación incluidos en Laravel.
Según Laravel, la forma más sencilla es pasar la nueva validación directamente al AppServiceProvider, entonces puedes traer el código del método de validación after
y modificarlo:
<?php
namespace App\Providers;
use Validator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('afterOrEqual', function($attribute, $value, $parameters, $validator) {
// Inicio código validación after
$this->requireParameterCount(1, $parameters, 'after');
if ($format = $this->getDateFormat($attribute)) {
return $this->validateAfterWithFormat($format, $value, $parameters);
}
if (! ($date = strtotime($parameters[0]))) {
return strtotime($value) > strtotime($this->getValue($parameters[0]));
}
return strtotime($value) > $date;
// Fin código validación after
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}
El problema aquí es llenar de mucho código el AppServiceProvider, para lo cual podrías incluir tus validadores personalizados en un servicio, e integrarlos todos de forma un poco más dinámica por medio de un ServiceProvider dedicado:
config/app.php
'providers' => [
...
App\Providers\ValidatorServiceProvider::class,
...
],
config/validator.php
<?php
return [
'path' => '\App\Services\Validators\\',
'validators' => [
'after_or_equal' => 'AfterOrEqualValidator',
// otros validadores personalizados
],
];
app/Providers/ValidatorServiceProvider.php
<?php
namespace app\Providers;
use Illuminate\Support\ServiceProvider;
use Validator;
class ValidatorServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$validators = config('validator.validators', []);
$validatorsPath = config('validator.path');
foreach ($validators as $name => $validator) {
Validator::extend($name, $validatorsPath . $validator . '@validate');
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
}
app/Services/Validators/Contracts/ValidatorContract.php
<?php
namespace App\Services\Validators\Contracts;
interface ValidatorContract
{
/**
* Validate a value.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return boolean
*/
public function validate($attribute, $value, $parameters);
}
app/Services/Validators/AfterOrEqualValidator.php
<?php
namespace App\Services\Validators;
use App\Services\Validators\Contracts\ValidatorContract;
class AfterOrEqualValidator implements ValidatorContract
{
/**
* Validar ....
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return boolean
*/
public function validate($attribute, $value, $parameters)
{
return $this->validateAfterOrEqual($attribute, $value, $parameters);
}
/**
* Validar ....
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validateAfterOrEqual($attribute, $value, $parameters)
{
// Inicio código validación after
// ** Modificar o reemplazar
$this->requireParameterCount(1, $parameters, 'after');
if ($format = $this->getDateFormat($attribute)) {
return $this->validateAfterWithFormat($format, $value, $parameters);
}
if (! ($date = strtotime($parameters[0]))) {
return strtotime($value) > strtotime($this->getValue($parameters[0]));
}
return strtotime($value) > $date;
// Fin código validación after
}
}
De cualquiera de las dos formas, el validador lo llamarías de la forma habitual:
"fechaRealEmbarqueCompra" => 'required|after_or_equal:fechaReservaCompra',