Get Info
You can get the basic user info (data from as_users
db table) like following:
$info = app('user')->getInfo($userId);
$info
will be an array containing following information:
$user_id = $info['user_id'];
$email = $info['email'];
$username = $info['username'];
$password = $info['password']
$confirmation_key = $info['confirmation_key'];
$confirmed = $info['confirmed'];
$password_reset_key = $info['password_reset_key'];
$register_date = $info['register_date'];
$user_role = $info['user_role'];
$last_login = $info['last_login'];
Note app('user')
will just resolve the instance of ASUser class for you (check container section for details). If you want to get the user's info from some other class that already have instance of ASUser class injected through the constructor (like ASComment
class for example), you can use it like usual: $this->users->getInfo($userId)
.
Update Info
You can update every user's information by passing it as an array item to updateInfo
method.
So, if you want to update user's email, you will do this:
app('user')->updateInfo($userId, array(
"email" => $newEmail
));
And if you want to update last_login, username and confirmation_key, you will just put it inside an array, and pass it to updateInfo function, like this
$user->updateInfo($userId, array(
"last_login" => $newLastLoginValue,
"username" => $newUsername,
"confirmation_key" => $newConfirmationKey
));
Note Don't forget that you can get the id for currently authenticated user from the container.
Get Details
You can get user details (data from as_user_details
db table) like following:
$details = app('user')->getDetails($userId);
$details
will be an array with following fields:
$first_name = $details['first_name'];
$last_name = $details['last_name'];
$address = $details['address'];
$phone = $details['phone'];
Update Details
Updating user details works the same as updating user info.
So, if you want to update address and phone, you can do it like following:
app('user')->updateDetails($userId, array(
"address" => $newAddress,
"phone" => $newPhone
));