‫Okay, so now we have at least we have some visualization that says we're logged in.
‫Now we want to make this log out work.
‫So let's go to the nav bar.
‫I'm actually I'm already in the nav bar.
‫And you can see we have the form here, the log out form.
‫And what we're going to want to do is make this make a Post request.
‫So let's say method equals post.
‫And the action is going to be slash auth slash log out.
‫So now we have to create a route for that.
‫So let's go to our routes file and we'll go.
‫Let's see down at the bottom here.
‫Just copy that down.
‫And this is going to be a Post request to auth logout.
‫And it's going to call user controller.
‫And then we'll have a logout method.
‫So let's close that up.
‫We can close that up.
‫And now let's go to our user controller.
‫And let's create the log out method in the class.
‫So log out a user and.
‫Kill session.
‫Okay, so return void.
‫So what we're going to do here is call the clear method in our session class.
‫So we'll say session clear.
‫And we want to clear the user session variable.
‫Now there is a cookie that we want to destroy as well.
‫So basically.
‫I want to just kill the session for everything so we could actually underneath that.
‫Say session.
‫Destroy or we actually we have a clear all we could do that.
‫Um.
‫Yeah.
‫Let's let's do clear all because that will clear that.
‫And it will destroy the session.
‫And then for the cookie.
‫Let's say params equals and then we can use session underscore get cookie params.
‫And the reason I want this is because this will give us the path in the domain that the cookie belongs
‫to.
‫So then we need to set cookie because we can't just we can't just call like clear cookie or something
‫like that.
‫We actually have to set it.
‫So we need the exact cookie name, which if we look in our application tab.
‫Let's see.
‫Application tab.
‫Where are you?
‫There you are.
‫So yeah it's going to be php slash id.
‫So in here let's say PHP sesh id.
‫So that's the cookie we want to set.
‫And then we're going to pass in for the value.
‫Just nothing.
‫So just an empty string.
‫And then the time we want to set that or the expiration we want to set that earlier to to now to when
‫this is to when this runs.
‫So we're going to say time minus and we'll do 86 400.
‫And then for the path we're going to use that params.
‫That's actually going to be an array.
‫And we're going to pass in here path.
‫And then for the domain we can say params.
‫And pass in here.
‫Domain.
‫So that should delete the cookie.
‫And yeah, we should log out and then let's redirect.
‫So we'll just redirect to, I guess, the home page.
‫Or you could redirect to to the login page.
‫I'm going to go to the home page.
‫So we'll save that and let's try it out.
‫I'm going to come back over here and reload.
‫And let's click Log Out.
‫There we go.
‫We got redirected.
‫We now see login and register if I reload.
‫Same thing.
‫So we're now logged out.
‫Now, we still don't have the ability to log in.
‫The only reason I was logged in is because I registered a new user, and we're essentially logging in
‫after the register because we create the session.
‫So now we just want a form this form right here to not do anything in the database except for validate
‫the user email address and password and then set the session.