本文整理汇总了PHP中app\models\User::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP User::toArray方法的具体用法?PHP User::toArray怎么用?PHP User::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::toArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the job.
*
* @param JWT $jwt
* @param Carbon $carbon
* @return String
*/
public function handle(JWT $jwt, Carbon $carbon)
{
$timestamp = $carbon->now()->timestamp;
$data = collect($this->user->toArray())->only('id')->merge(compact('timestamp'));
$token = $jwt->encode($data, env('APP_KEY'));
/**
* Save token on the user model
*/
if ($this->saveToken) {
$this->user->setAttribute('api_token', $token);
$this->user->save();
}
return $token;
}
示例2: sendResetPasswordInfo
public function sendResetPasswordInfo(User $user, PasswordResetToken $passwordResetToken)
{
Mail::queue('emails.reset_password_info', ['user' => $user, 'passwordResetToken' => $passwordResetToken, 'link' => $passwordResetToken->getResetPasswordLink()], function ($message) use($user, $passwordResetToken) {
$transParams = array_dot($user->toArray());
$transParams['app_name'] = trans('base.app.name');
$message->to($passwordResetToken->email, $user->username)->subject(trans('reset_password.request_code.email.subject', $transParams));
});
}
示例3: fillFromEloquent
public function fillFromEloquent(User $user)
{
$this->eloquent = $user;
$attributes = $user->toArray();
if (isset($this->username)) {
unset($attributes['username']);
}
$this->fill($attributes);
}
示例4: transform
public function transform(User $user)
{
return $user->toArray();
}
示例5: generateUserToken
/**
* Generate a jwt token for user
* @param User $user
* @param bool $rememberMe
* @param bool $jwtCookie
* @return string
*/
public function generateUserToken($user, $rememberMe = false, $jwtCookie = false)
{
$data = ["sub" => (int) $user->id, "user" => $user->toArray(), "rememberMe" => (int) $rememberMe, "auth" => $this->calculateAuthHash($user)];
// compute exp
$ttl = $rememberMe ? $this->ttlRememberMe : $this->ttl;
$data["exp"] = is_string($ttl) ? strtotime($ttl) : time() + $ttl;
// compute csrf if using cookie
if ($jwtCookie) {
$data["csrf"] = $this->request->getCsrfToken();
}
$token = $this->encode($data);
if ($jwtCookie) {
$this->addCookieToken($this->tokenParam, $token, $data["exp"]);
}
return $token;
}
示例6: store
/**
* store a resource
* @param Request $this->request http request
* @param mixed $id id of the resource for updating
* @return jsend jsend with newly stored source
*/
function store($id = null)
{
////////////////
// Load Data //
////////////////
if ($id) {
$data = Model::find($id);
if (!$data) {
return app()->abort(404);
}
} else {
$data = new Model();
}
///////////////////////////////////
// Assign posted data to Data //
///////////////////////////////////
$data->fill($this->request->input());
///////////////////////
// EMBED IMAGES //
///////////////////////
foreach ($this->request->input('images') as $x) {
$images[] = new Image($x);
}
if (!$data->syncImages($images)) {
return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
}
///////////////////////
// EMBED AUTH //
///////////////////////
foreach ($this->request->input('auths') as $x) {
$auths[] = new Auth($x);
}
if (!$data->syncAuths($auths)) {
return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
}
///////////////////////
// EMBED ACCOUNT //
///////////////////////
foreach ($this->request->input('account_connects') as $x) {
$accounts[] = new AccountConnect($x);
}
if (!$data->syncAccountConnects($accounts)) {
return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
}
///////////
// Store //
///////////
if ($data->save()) {
/////////////////////
// Return Response //
/////////////////////
return response()->json(JSend::success(['data' => $data->toArray()])->asArray());
} else {
return response()->json(JSend::fail($data->getErrors())->asArray());
}
}