本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::first方法的具体用法?PHP Model::first怎么用?PHP Model::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::first方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: first
/**
* Retrieve first data of repository
*
* @param array $columns
*
* @return mixed
*/
public function first($columns = ['*'])
{
$this->applyCriteria();
$this->applyScope();
$results = $this->model->first($columns);
$this->resetModel();
return $this->parserResult($results);
}
示例2: sendResetPasswordEmail
/**
* Generate and send a email with reset password instructions.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @param array $conditions WHERE conditions to locate user. Format: ['column' => 'value']
* @return bool
* @throws \Nodes\Backend\Auth\Exception\ResetPasswordNoUserException
*/
public function sendResetPasswordEmail(array $conditions)
{
// Validate conditions
if (empty($conditions)) {
return false;
}
// Add conditions to query builder
foreach ($conditions as $column => $value) {
$this->userModel = $this->userModel->where($column, '=', $value);
}
// Retrieve user with conditions
$user = $this->userModel->first();
if (empty($user)) {
$this->errors->add('no-user-found', 'Could not find any user with those credentials.');
return false;
}
// Generate reset password token
$token = $this->generateResetPasswordToken($user);
// Send e-mail with instructions on how to reset password
\Mail::send(['html' => config('nodes.backend.reset-password.views.html', 'nodes.backend::reset-password.emails.html'), 'text' => config('nodes.backend.reset-password.views.text', 'nodes.backend::reset-password.emails.text')], ['user' => $user, 'domain' => config('app.url'), 'token' => $token, 'expire' => config('nodes.backend.reset-password.expire', 60), 'project' => config('nodes.project.name')], function ($message) use($user) {
$message->to($user->email)->from(config('nodes.backend.reset-password.from.email', 'no-reply@nodes.dk'), config('nodes.backend.reset-password.from.name', 'Nodes'))->subject(config('nodes.backend.reset-password.subject', 'Reset password request'));
});
return true;
}
示例3: sendResetPasswordEmail
/**
* Generate and send a email with reset password instructions.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @param array $conditions WHERE conditions to locate user. Format: ['column' => 'value']
* @throws \Nodes\Api\Auth\Exceptions\ResetPasswordNoUserException
*/
public function sendResetPasswordEmail(array $conditions)
{
// Validate conditions
if (empty($conditions)) {
throw new ResetPasswordNoUserException('Conditions can\'t be empty');
}
// Add conditions to query builder
foreach ($conditions as $column => $value) {
$this->authModel = $this->authModel->where($column, '=', $value);
}
// Retrieve user with conditions
$user = $this->authModel->first();
if (empty($user)) {
throw new ResetPasswordNoUserException('Could not find any user with those credentials');
}
// Generate reset password token
$token = $this->generateResetPasswordToken($user);
// Generate reset password domain
$domain = env('NODES_ENV', false) ? sprintf('https://%s.%s', env('APP_NAME'), env('APP_DOMAIN')) : config('app.url');
// Send e-mail with instructions on how to reset password
Mail::send(['html' => config('nodes.api.reset-password.views.html', 'nodes.api::reset-password.emails.html'), 'text' => config('nodes.api.reset-password.views.text', 'nodes.api::reset-password.emails.text')], ['user' => $user, 'domain' => $domain, 'token' => $token, 'expire' => config('nodes.api.reset-password.expire'), 'senderName' => config('nodes.api.reset-password.from.name') != 'Nodes' ? config('nodes.api.reset-password.from.name') : config('nodes.project.name')], function ($message) use($user) {
$message->to($user->email)->from(config('nodes.api.reset-password.from.email', 'no-reply@nodes.dk'), config('nodes.api.reset-password.from.name', 'Nodes'))->subject(config('nodes.api.reset-password.subject', 'Reset password request'));
});
}
示例4: extractModelAndKeys
/**
* Extract the model instance and model keys from the given parameters.
*
* @param string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection $model
* @param array|null $keys
* @return array
*/
public static function extractModelAndKeys($model, array $keys = null)
{
if (is_null($keys)) {
if ($model instanceof Model) {
return [$model, [$model->getKey()]];
}
if ($model instanceof Collection) {
return [$model->first(), $model->modelKeys()];
}
} else {
if (is_string($model)) {
$model = new $model();
}
return [$model, $keys];
}
}
示例5: first
/**
* Returns the first record in the database.
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function first()
{
return $this->model->first();
}