Event::listen('illuminate.query', function($sql)
{
var_dump($sql);
});
Paste this to routes.php and it will display all the queries that are ran.
Or use this to show your queries: https://github.com/barryvdh/laravel-debugbar
Check your app/config/auth.php file to see what auth driver you have defined.
I am not 100% but I am pretty sure that if you choose
'driver'=>'eloquent'
then you can define a model that isn't tied to any database, which should in turn should prevent any DB queries.
If you look at Guards user method you'll see that if you call user() it will hit the database the first time and store that user so that all subsequent calls will reuse that user object.
I wrote a custom Auth driver to authenticate with a webservice and I noticed Auth::attempt will return a valid user but Auth.Guard wont store that user for subsequent requests. Doing Auth::user() will go an re-authenticate with my webservice everytime. I bypassed this by saving a serialized user object in the session but would much rather see if Auth.guard can store the logged in user on it's own. My custom AuthProvider for reference below
class RestAuthProvider implements UserProviderInterface { /** * The user object. */ private $user;
/**
* Constructor
*
* @return void
*/
public function __construct()
{
if (!empty(Session::get('user'))) {
$this->user = unserialize(Session::get('user'));
} else {
$this->user = null;
}
}
/**
* Retrieve a user by their unique identifier.
*
* @param mixed $id
* @return \Illuminate\Auth\UserInterface|null
*/
public function retrieveById($id)
{
try {
// check if we have a user
if (is_null($this->user)) {
$this->user = WebserviceController::getUserAccount($id);
Session::set('user', serialize($this->user));
}
// return user object
return $this->user;
} catch(\GuzzleHttp\Exception\ClientException $e) {
Log::error($e->getRequest());
if ($e->hasResponse()) {
Log::error($e->getResponse());
}
}
}
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Auth\UserInterface|null
*/
public function retrieveByCredentials(array $credentials)
{
// make login request via Guzzle
try {
$user = WebserviceController::loginUser($credentials);
// store user in session
Session::set('user', serialize($this->user));
// returns GenericUser object
return $user;
} catch(\GuzzleHttp\Exception\ClientException $exception) {
Log::error($exception->getRequest());
if ($exception->hasResponse()) {
Log::error($exception->getResponse());
}
}
}
/**
* Validate a user against the given credentials.
*
* @param \Illuminate\Auth\UserInterface $user
* @param array $credentials
* @return bool
*/
public function validateCredentials(UserInterface $user, array $credentials)
{
return true;
}
/**
* Needed by Laravel 4.1.26 and above
*/
public function retrieveByToken($identifier, $token)
{
return new \Exception('retrieve by token not implemented');
}
/**
* Needed by Laravel 4.1.26 and above
*/
public function updateRememberToken(UserInterface $user, $token)
{
print_r("update token".$user.$token); die;
}
damienadermann said:
If you look at Guards user method you'll see that if you call user() it will hit the database the first time and store that user so that all subsequent calls will reuse that user object.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community