Ad
Laravel 5: The Difference Between Auth::guard($this->getGuard())->login($user); And Auth()->login($user);
What is the difference between:
Auth::guard($this->getGuard())->login($user);
and
auth()->login($user);
? For example, in PasswordController.php we can have:
protected function resetPassword($user, $password)
{
$user->password = $password;
$user->save();
Auth::guard($this->getGuard())->login($user);
}
or
protected function resetPassword($user, $password)
{
$user->password = $password;
$user->save();
auth()->login($user);
}
(in this case, we create a mutator in Users.php to bcrypt password AND NOT in resetPassword($user, $password) as it is by default)
In particular, what is guard($this->getGuard()), what does it do (guard(), getGuard())?
Ad
Answer
There is no difference, the auth
function is just a helper that returns an instance of \Illuminate\Contracts\Auth\Guard
.
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/helpers.php
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad