Support the ongoing development of Laravel.io →
Authentication Security Validation
Last updated 1 year ago.
0

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', ]); 
}  
0

Sign in to participate in this thread!

Eventy

Your banner here too?

eurochoi eurochoi Joined 26 Jun 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.