I cannot override a method of a trait in my Controller class. Here is an example of my trait method:
protected function resetPassword($user, $password)
{
$user->password = bcrypt($password);
$user->save();
Auth::login($user);
}
And here is my Controller:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
use ResetsPasswords {
resetPassword as newReset;
}
/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
protected function resetPassword($user, $password)
{
}
}
I found one example, but I am not sure that I am on a right way.
As you have already done it yourself, you need to alias framework trait's resetPassword
method and then implement your own:
namespace App\Http\Controllers\Auth;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
use ResetsPasswords {
resetPassword as frameworkResetPassword;
}
protected function resetPassword($user, $password)
{
// Do your custom password reset logic here
$user->password = bcrypt($password);
$user->save();
Auth::login($user);
// Then you can pass the work over to framework's implementation
// if that's needed.
// $this->frameworkResetPassword($user, $password);
}
}
By the way, Laravel's own password reset functionality supports logging users in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With