/** * 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); }
/** * Generate and send a email with reset password instructions. * * @author Morten Rugaard <*****@*****.**> * * @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', '*****@*****.**'), config('nodes.backend.reset-password.from.name', 'Nodes'))->subject(config('nodes.backend.reset-password.subject', 'Reset password request')); }); return true; }
/** * Generate and send a email with reset password instructions. * * @author Morten Rugaard <*****@*****.**> * * @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', '*****@*****.**'), config('nodes.api.reset-password.from.name', 'Nodes'))->subject(config('nodes.api.reset-password.subject', 'Reset password request')); }); }
/** * 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]; } }
/** * Returns the first record in the database. * * @return \Illuminate\Database\Eloquent\Model */ public function first() { return $this->model->first(); }