app/Http/Controllers/Auth/RegisterController.php
/**
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
@param Request $request
@return JsonResponse
@throws ValidationException
@param Request $request @return JsonResponse @throws ValidationException
public function register(Request $request): JsonResponse
    {
        $user = Auth::user();
        if ($user) {
            return response()->json(null, 401);
        }
        $messages = [
            'name.unique' => 'Seline kasutajanimi on juba võetud!',
            'email.unique' => 'Seline e-post on juba kasutusel!',
            'password.min' => 'Parool peab olema vähemalt 6 tähemärki!',
        ];
        $this->validate($request, [
            'name' => 'required|max:64|unique:users',
            'email' => 'required|email|max:64|unique:users',
            'password' => 'required|min:6'
        ], $messages);
        $data = [
            'name' =>  $request->post('name'),
            'email' =>  $request->post('email'),
            'password' => Hash::make($request->post('password')),
            'role' => 'regular',
            'real_name' => ''
        ];
        $user = User::create($data);
        event(new Registered($user));
        return response()->json('success');
    }
public function register ( Request $ request ) : JsonResponse { $ user = Auth :: user ( ) ; if ( $ user ) { return response ( ) -> json ( null , 401 ) ; } $ messages = [ 'name.unique' => 'Seline kasutajanimi on juba võetud!', 'email.unique' => 'Seline e-post on juba kasutusel!' , 'password.min' => 'Parool peab olema vähemalt 6 tähemärki!', ] ; $ this -> validate ( $ request , [ 'name' => 'required|max:64|unique:users' , 'email' => 'required|email|max:64|unique:users' , 'password' => 'required|min:6' ] , $ messages ) ; $ data = [ 'name' => $ request -> post ( 'name' ) , 'email' => $ request -> post ( 'email' ) , 'password' => Hash :: make ( $ request -> post ( 'password' ) ) , 'role' => 'regular' , 'real_name' => '' ] ; $ user = User :: create ( $ data ) ; event ( new Registered ( $ user ) ) ; return response ( ) -> json ( 'success' ) ; }
@param Request $request
 @return JsonResponse
 @throws ValidationException
@param Request $request @return JsonResponse @throws ValidationException