Support the ongoing development of Laravel.io →
Authentication Security
Last updated 2 years ago.
0

Do you every time get the error...

Probably while user model is calling , an exception is threw.

Here is Auth::logout() method..

/* \Illuminate\Auth\Guard */
	/**
	 * Log the user out of the application.
	 *
	 * @return void
	 */
	public function logout()
	{
		$user = $this->user();  // I think that  this point returns throw "Error connecting to database"

		// If we have an event dispatcher instance, we can fire off the logout event
		// so any further processing can be done. This allows the developer to be
		// listening for anytime a user signs out of this application manually.
		$this->clearUserDataFromStorage();

		if ( ! is_null($this->user))
		{
			$this->refreshRememberToken($user);
		}

		if (isset($this->events))
		{
			$this->events->fire('auth.logout', array($user));
		}

		// Once we have fired the logout event we will clear the users out of memory
		// so they are no longer available as the user is no longer considered as
		// being signed into this application and should not be available here.
		$this->user = null;

		$this->loggedOut = true;
	}

Last updated 2 years ago.
0

Yes every time I logout!

It is strange because if I return to the login page, the user seems to be logged out. I can login correctly again.

I have also tryed this:

if (Auth;;check()) { Auth:logout(); }

But anything changed!

Always "Error connecting to database"

Last updated 2 years ago.
0

Maybe my db structure is not compatible?

is there a standard schema to check?

Last updated 2 years ago.
0

I had the same problem because I too was getting the same error as you. Since you posted this 2 months ago, I am assuming that you have already figured out the answer but I am posting my solution here just in case other people have trouble figuring out the answer.

The user table must have updated_at column (datetime). Using Eloquent, all tables must have created_at and updated_at column. In this case, Auth can log out successfully but it cannot update the column updated_at if there isn't any and that is where "error connecting to database" comes from (You can find it in laravel.log).

If there is a problem logging in a user (Auth::attempt), Eloquent assumes default primary key called "id". If the primary key in your table is not "id", then add the following in User model.

protected $primaryKey = 'your primary key column';

Note that "K" in primaryKey is uppercase.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.