app/Services/UserService.php
public function create(string $user_name, string $real_name, string $email, string $password): User
    {
        DB::table('user')->insert([
            'user_name' => $user_name,
            'real_name' => $real_name,
            'email'     => $email,
            'password'  => password_hash($password, PASSWORD_DEFAULT),
        ]);

        $user_id = (int) DB::connection()->getPdo()->lastInsertId();

        return new User($user_id, $user_name, $real_name, $email);
    }
public function create(string $user_name, string $real_name, string $email, string $password): User
    {
        DB::table('user')->insert([
            'user_name' => $user_name,
            'real_name' => $real_name,
            'email'     => $email,
            'password'  => password_hash($password, PASSWORD_DEFAULT),
        ]);

        $user_id = (int) DB::connection()->getPdo()->lastInsertId();

        return new User($user_id, $user_name, $real_name, $email);
    }
public function create ( string $ user_name , string $ real_name , string $ email , string $ password ) : User { DB :: table ( 'user' ) -> insert ( [ 'user_name' => $ user_name , 'real_name' => $ real_name , 'email' => $ email , 'password' => password_hash ( $ password , PASSWORD_DEFAULT ) , ] ) ; $ user_id = ( int ) DB :: connection ( ) -> getPdo ( ) -> lastInsertId ( ) ; return new User ( $ user_id , $ user_name , $ real_name , $ email ) ; }
Create a new user.
The calling code needs to check for duplicates identifiers before calling
this function.

@param string $user_name
@param string $real_name
@param string $email
@param string $password

@return User
Create a new user . The calling code needs to check for duplicates identifiers before calling this function .