Customizing Jetstream Actions0:00
So far we've taken a look at customizing our Vues and our Routes. Now for customizing the actual functionality, Jetstream and Fortify exposes a set of actions that you can customize to your liking. So if you look at our code, you'll see a folder for actions, and a folder for Fortify and Jetstream, and you'll see classes corresponding to the different features. So they're pretty self-explanatory, let's go ahead and go through one together. So one common thing that you might want to customize is the register process, and you might want to add a new field. So let's go ahead and do that. So here's the createNewUser action, which we can customize, and we will.
Adding Company to Registration0:30
So let's go ahead and do that. So here's the create new User action, which we can customize, and we will. So let's do that. Let's go to our code, and let's add a new field for register here. So I'm going to add a new one called company right underneath our name here. So let's do that. Start in the Vue. Let's go to our register.vue, and it's within resources, Vue is off. And right underneath name, let's go ahead and make a new one called company. Okay.
Okay. And let's see how that looks. Looks good. It should be a capital. And now let's go ahead and make a new migration to add that field to our database table. So let's say php artisan make:migration. Let's say update_users_table, add company field. Okay. And let's go ahead and go to that file, update_users_table. Okay.
And let's go ahead and go to that file, update users table. Okay. And I'm just going to paste in some code here. Okay. And we're just adding a new field called company. I'm putting it after the email, verify that column, and we're making it nullable. And let me paste in some code for the drop method or the down method as well. So we can drop that column if we roll back. Okay. And let's go ahead and migrate:fresh.
Okay. And let's go ahead and migrate fresh. And let's go to the User model. And I believe I have to add, yeah, let's add company here to the fillable array. And now let's see if that new company field is being passed through. So this is a method that has the validation, but let's see if we're getting the company field. So I'm just going to dd(request()->input()) here and see if this works. And let me just fill this out. And let's see if the company field is being passed through.
And let me just fill this out. And let's see if the company field is being passed through. And it is cool. So now we just have to modify this code accordingly and add the company field. So validate the company and say company. And the validation rules are fine for that. And let's add it here when we're creating a new User. So company is going to be inputCompany, which is just the request being passed through. And I believe there's one here, too, for creating the team. No, it's just for team, that's fine.
And I believe there's one here, too, for creating the Team. No, it's just for Team, that's fine. So let's save that. And let's try it again in our form. And let's see if we get a new User. Okay. So we're logged in. And let's check our database to make sure the company was passed through. And it was. So pretty straightforward.
Updating Profile Company Field3:55
And it was. So pretty straightforward. Let's go ahead and take a look at one more action here. And that is updating the User profile. So we want to add the profile or the company within here. So let's do that as well. So I'm not sure what the view is called. So let's just go to that folder views. And I believe it's called profile and update profile information. So that's the photo.
And I believe it's called profile and update profile information. So that's the photo. And the name is right here. So let's add one for name. I mean, for company, company here. And let me just add company here, changes to company. And let me just make this capital. And that should render correctly. Okay. And now let's go ahead and modify the action.
Okay. And now let's go ahead and modify the action. So it's update User profile information right here. And let's just add company wherever we need it. So here, company. And we have it here. Input company. And I believe there's one more down here. Yeah, there's one for updating the verified User. So let's add it here as well.
Logging Team Invitations6:05
So let's say we wanted to maybe send an email after someone invites you to a team. I'm not going to do that here. But say you want to do that, it's going to make use of the log here and say log info. Let's say userName, and let's say added you to a team added the name of the person who we're adding. So that's going to be new teamMemberName. And let's just say to a team. And can we get the teamName as well? Not sure. Let's see.
Not sure. Let's see. Let me import log and we just dined up team here. Okay, and let's try it out. Actually, I have to make a new User as well. So let me just grab this open incognito. And let's go ahead and make a new User. Let's go to register. Okay, so I added a new User. And let's go ahead and add that User.
Okay, so I added a new User. And let's go ahead and add that User. So let's go to teams here. And I am going to add that new User I just made. And let's see what kind of team we get. So yeah, it's a Team model. And I believe there's a teamName. Yeah, teamName. So we can say added User name added new TeamMember name to a Team named. And then we can do teamName.
So we can say added userName added new team member name to a team named teamName. And then we can do teamName. Okay, let's see if this works. Let's remove the dine dump. And let's try this out. Let's go back. And let's go back to teams. And let's invite that user. And this hopefully should work. Okay, and that user was added here.
Customizing Login Pipeline7:58
And this hopefully should work. Okay, and that user was added here. Let's check our logs. So Laravel.log. And if you scroll down, there we go. Andre added user to a team named Andre's team. And one more thing I want to take a look at is customizing the authentication process. So if you look at the actions here, there's nothing dealing with the actual logging in of the user. So that's because you can customize that using authentication pipelines.
of the User. So that's because you can customize that using authentication pipelines. So if you look at this section and scroll down to customizing the authentication pipeline, you can do it like this. So as the name implies, it makes use of pipelines. And if you're not familiar with that, it's just a set of classes that have a handle method. And Laravel goes to them one by one. So think of it like middleware. So it goes through this, and it goes through this, and it goes through this, and then it goes through this.
So it goes through this, and it goes through this, and it goes through this, and then it goes through this. So I believe what they have here in the docs is the default pipeline. So let's take a look at the routes. So remember, I published the routes in a previous video, or you can just look at the routes in the package folder. Where is it? So routes, Fortify, okay. And if you look at the login right here, we have AuthenticatedSessionController. And this lives in the package directory, but we can still take a look at it.
And if you look at the login right here, we have AuthenticatedSessionController. And this lives in the package directory, but we can still take a look at it. And if you scroll down, you'll see that it has pretty much the same pipeline that we see in the documentation. So ensureLogin is not throttled. Oops, let's take a look at this ensureLogin is not throttled, then the twoFactorAuthAttempt to authenticate, and then prepareAuthenticatedSession. So let's go ahead and try this and add one more class to this pipeline. So this goes into the boot method of your JetstreamServiceProvider. So let's do that.
So this goes into the boot method of your JetstreamServiceProvider. So let's do that. Let's go to JetstreamServiceProvider, the one in our application, let's go to our boot method. And let's put it right here. Let's make sure to import Fortify. And we have to import all of this stuff too. So let's grab this and put up here, maybe some duplicates here. Yeah, Fortify is already imported. So let's remove that.
Yeah, Fortify is already imported. So let's remove that. And let's add one more class to this pipeline, just to see if it works. So like I said, you can think of pipelines as middleware. So they should have a handle method. So let's take a look at one of them. And there is a handle method here. So you can just copy this class and make your own or if you want, you can just make use of middleware. And that's what I'll do here.
of middleware. And that's what I'll do here. php artisan make:middleware. Let's call it LogLogin. Sorry, did I type that wrong? make:middleware. Okay. And you don't have to make use of middleware, you can just make a class if you want. But I'm just using the scaffolding. So the class is created for me.
But I'm just using the scaffolding. So the class is created for me. So let's say log login. And we'll just put something in here. So again, it's just log info. And make sure to import log and say this user is logging in. And just grab the user name, or the request name, or the request email, because this is going to be run after the user attempts to log in from the login form. Okay, I thought I imported log. And what seems to be the problem here, I forgot to add a dot.
Okay, I thought I imported log. And what seems to be the problem here, I forgot to add a dot. So let's do that. Okay. And let's add this class to our pipeline. So back to JetstreamServiceProvider. And we can add this anywhere in our pipeline. So let's say log login. So again, this doesn't have to be middleware, I just used it. So it's scaffolded out the class and the handle method for me.
So again, this doesn't have to be middleware, I just used it. So it's scaffolded out the class and the handle method for me. So let's go ahead and import that. I believe that imported it up here. Yep, right there. And yeah, this should work. So now let's try to log in. So I am going to log out here. And log in. Let's see if it gets logged.
And log in. Let's see if it gets logged. Okay. And we are logged in. Let's check our Laravel log. And scroll down. Here we go. Cool. And one more quick reminder for any custom functionality that you want to add, we have access to the views and the routes.
Extending Views with Livewire12:52
And one more quick reminder for any custom functionality that you want to add, we have access to the views and the routes. So you're free to do whatever you like. So for example, if I wanted to add something within the profile here, maybe something within here, we could do that. So let's go back to that view. Where is it? This one. Update profile information. Or sorry, let's go to the show.blade.php, which is the shell of that view.
Update profile information. Or sorry, let's go to the show.blade.php, which is the shell of that view. And say we wanted to add something right underneath here. Something here. Let's just add something here. We can do that. And there it is. So say for example, I wanted to add a Livewire component. We are free to do that. Let's do php artisan make:livewire.
We are free to do that. Let's do php artisan Livewire make. Let's make a counter. Okay. And let's open that up. Or let's actually render it here. Say Livewire counter. And let's open that up. Right here. And counter goes here.
Right here. And counter goes here. Actually, let's just make one real quick. count. Let's go to the class. Actually, we need buttons. div. And let's add our buttons here. I'm not going to style it. button increment.
I'm not going to style it. Button increment. Button decrement. Let's do wire:click on these and let's add a method. wire:click increment. And we'll make this one decrement. And let's quickly go to our counter.php. Let's make a piece of state. Start it at 0. And let's make those two methods.
Start it at zero. And let's make those two methods. increment. And decrement. This count plus plus. And decrement is this count minus minus. Okay. If I did everything correctly, this should work. As you expect as a Livewire component. And the buttons are not rendering.
As you expect as a Livewire component. And the buttons are not rendering. Or they are. I don't know what I'm talking about. Increment. Decrement. So yeah. You have full control over your application. And you can just keep adding functionality as you see fit.
