Create custom validaton rule like:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Validator::extend('email_domain', function($attribute, $value, $parameters, $validator) {
$allowedEmailDomains = ['example.com', 'sub.example.com'];
return in_array( explode('@', $parameters[0])[1] , $allowedEmailDomains);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
and then validate:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email_domain:' . $data['email'] . '|max:255|unique:users',
'password' => 'required|min:6|confirmed', ]);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community