app/Http/Controllers/Auth/RegisteredUserController.php
/**
     * Handle an incoming registration request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse
     *
     * @throws \Illuminate\Validation\ValidationException
     */
Handle an incoming registration request.


Handle an incoming registration request .
public function store(Request $request)
    {
        if(Gate::allows('first-register'))
        {
            $request->validate([
                'name' => ['required', 'string', 'max:255'],
                'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
                'password' => ['required', 'confirmed', Rules\Password::defaults()]
            ]);
            $user = User::create([
                'name' => $request->name,
                'email' => $request->email,
                'password' => Hash::make($request->password),
                'access_level' => 1
            ]);
            event(new Registered($user));
            Auth::login($user);
        }
        else
        {
            Gate::authorize('register');
            $request->validate([
                'name' => ['required', 'string', 'max:255'],
                'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
                'password' => ['required', 'confirmed', Rules\Password::defaults()],
                'access_level' => ['required', 'integer', 'max:3']
            ]);
            $user = User::create([
                'name' => $request->name,
                'email' => $request->email,
                'password' => Hash::make($request->password),
                'access_level' => $request->access_level
            ]);
            event(new Registered($user));
        }
        return redirect(RouteServiceProvider::HOME);
    }
public function store ( Request $ request ) { if ( Gate :: allows ( 'first-register' ) ) { $ request -> validate ( [ 'name' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , 'unique:users' ] , 'password' => [ 'required' , 'confirmed' , Rules \ Password :: defaults ( ) ] ] ) ; $ user = User :: create ( [ 'name' => $ request -> name , 'email' => $ request -> email , 'password' => Hash :: make ( $ request -> password ) , 'access_level' => 1 ] ) ; event ( new Registered ( $ user ) ) ; Auth :: login ( $ user ) ; } else { Gate :: authorize ( 'register' ) ; $ request -> validate ( [ 'name' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , 'unique:users' ] , 'password' => [ 'required' , 'confirmed' , Rules \ Password :: defaults ( ) ] , 'access_level' => [ 'required' , 'integer' , 'max:3' ] ] ) ; $ user = User :: create ( [ 'name' => $ request -> name , 'email' => $ request -> email , 'password' => Hash :: make ( $ request -> password ) , 'access_level' => $ request -> access_level ] ) ; event ( new Registered ( $ user ) ) ; } return redirect ( RouteServiceProvider :: HOME ) ; }
Handle an incoming registration request.
Handle an incoming registration request .