This episode is for members only

Sign up to access "Build a Starter Kit With Inertia and Fortify" right now.

Get started
Already a member? Sign in to continue
Playing
11. Signing out

Episodes

0%
Your progress
  • Total: 5h 21m
  • Played: 0m
  • Remaining: 5h 21m
Join or sign in to track your progress

Transcript

00:00
Okay, so pretty annoying that we can't sign out at the moment, let's go ahead and add this in.
00:04
This is actually very straightforward. Okay, first of all, let's go over to our root list again and see which root we need to call here. And if we scroll up, sure enough, we've got logout. Now, this actually does have a name, so we can reference this by name, which is really good.
00:19
So how are we going to do this? Well, obviously, this needs to happen from our navigation, and that needs to happen from this sign out link just here. So if we go over to that sign out link, at the moment, this is a link.
00:32
Now, we don't want to link through to this because if we look at this, this is a post route. So we want to post through to this. Now, I'm going to change this over to a button. So when we click on it, we can perform some sort of action.
00:46
So let's swap that over to a button, get rid of the href. And then we'll just do a V on click. And then we'll have some sort of function within our navigation, which we can call. And then using inertia's router, send a post request through to logout.
01:01
So let's just call this logout. That kind of makes sense. And then at the top here, we'll go ahead and add this function in. So let's create this out here.
01:10
And that's pretty much it. In here, we can send that request through. Now, because we've changed this over to a button, it's going to look a little bit weird. You can see that it's not quite full width.
01:19
So let's go back to that button really quickly. And let's go ahead and set this to have a width of full. That's not going to really help us, because by default, button text is centered. So we can just add a text left here.
01:31
And that's going to make it look like a standard link. So when we click on that, that is now invoking that function. So the question is, because we're not going through to a link, how do we send a request with inertia without using a form
01:43
or clicking on a link to actually send a request through? Well, in this case, we can just bring in inertia's router. And then say something like router, post, get, patch, whatever we need to do. And then just go through to a specific URL.
01:57
Now, in our case, that's logout. So we've already seen that just here. And it's named, which means that we can just pass through our route helper directly in here and reference the name logout.
02:08
Now, that is all we need to do. When we post this through, of course, we're going to be unauthenticated. And then it's going to redirect us over to our page that we specified in our route service provider.
02:20
So let's try this out. I'm going to go ahead and click on this. And there we go. We're redirected the home page.
02:25
We are now signed out. Let's go ahead and sign in again just for fun. And we'll see that works. And we can now sign in and sign out, which is really useful.
40 episodes5 hrs 21 mins

Overview

Let’s build our own Laravel starter kit with Inertia and include all the features you’d expect. We’ll implement authentication, email verification, profile photo uploads, two factor authentication, and more.

Fortify is a frontend agnostic authentication package for Laravel, meaning most of the work is done for us — we just need to build the frontend and make requests to the endpoints that Fortify registers.

Once you’re done, you’ll have a clean slate for building your next project, with the ability to control everything in your own starter kit.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.