38 lines
822 B
PHP
38 lines
822 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Providers;
|
||
|
|
|
||
|
|
use Carbon\Carbon;
|
||
|
|
use Illuminate\Support\Facades\Validator;
|
||
|
|
use Illuminate\Support\ServiceProvider;
|
||
|
|
|
||
|
|
class AppServiceProvider extends ServiceProvider
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Register any application services.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function register()
|
||
|
|
{
|
||
|
|
//
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Bootstrap any application services.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function boot()
|
||
|
|
{
|
||
|
|
Validator::extend('lessThan', function ($attribute, $value, $parameters)
|
||
|
|
{
|
||
|
|
$minAge = ( ! empty($parameters)) ? (int) $parameters[0] : 14;
|
||
|
|
return Carbon::parse($value)->age <= $minAge;
|
||
|
|
|
||
|
|
// or the same using Carbon:
|
||
|
|
// return Carbon\Carbon::now()->diff(new Carbon\Carbon($value))->y >= $minAge;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|