AppServiceProvider.php
Go to the documentation of this file.
1 <?php
2 namespace App\Providers;
3 
4 use Validator;
6 
14 class AppServiceProvider extends ServiceProvider
15 {
23  public function boot()
24  {
25 
26  // Email array validator
27  Validator::extend('email_array', function($attribute, $value, $parameters, $validator) {
28  $value = str_replace(' ','',$value);
29  $array = explode(',', $value);
30 
31  foreach($array as $email) //loop over values
32  {
33  $email_to_validate['alert_email'][]=$email;
34  }
35 
36  $rules = array('alert_email.*'=>'email');
37  $messages = array(
38  'alert_email.*'=>trans('validation.email_array')
39  );
40 
41  $validator = Validator::make($email_to_validate,$rules,$messages);
42 
43  if ($validator->passes()) {
44  return true;
45  } else {
46  return false;
47  }
48 
49  });
50  }
51 
57  public function register()
58  {
59  //
60  }
61 }
This service provider handles a few custom validation rules.
boot()
Custom email array validation.