how to make a global array variable in laravel controller
i tried this
class AuthController extends Controller
{
public $loginCred = [];
public function postLogin(Request $request){
$request['email'] = $loginCred['email'];
$request['password'] = $loginCred['password'];
// a bunch of code later
return redirect()->away($authUrl);
}
public function callback(Request $request)
{
$loginCred->session()->regenerate();
return redirect()->route('home');
}
}
but it gives ErrorException "Undefined variable $loginCred"
2
Answers
If the defining process is reversed like this:
It works on my machine, the login passed, and the error is gone.
If you define a variable in a controller, your functions need to use $this->variable to access it.
Therefore, you should use:
to access your $loginCred variable.