Tuesday, March 21, 2017

Laravel 5 Can't Access Trait Functions

any idea as to why I can't access a the ResetsPasswords trait functions?

It's just on this controller, because on other controllers I can access the traits functions perfectly.

Basically I duplicated the auth code because I have two types of users, Candidates and Companies. I'm trying to reset the password for Candidates. I can register and login easily with both types.

Here is the code:

namespace App\Http\Controllers\CandidateUserAuth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\ResetsPasswords;

use Illuminate\Support\Facades\Config;

class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/

use ResetsPasswords;

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    //Change the default guard and password set in auth.php
    Config::set("auth.defaults.guard","candidate");
    Config::set("auth.defaults.passwords","candidates");
    $this->middleware('guest');
}

//Check to see if really needed
protected function guard()
{
    return Auth::guard('candidates');
}

//Override of original function in the trait ResetsPasswords
public function showResetForm(Request $request, $token = null)
{
    return view('candidate-auth.passwords.reset')->with(
        ['token' => $token, 'email' => $request->email]
    );
}
}



via Adam Silva

Advertisement