Creating Profile Page0:00
Okay, let's take a look at updating our profile information and our password in Fortify. So first let's take a look at how it looks in Jetstream. Here you can update your profile information and down here you can update your password. So Fortify has the routes and controllers available. So let's go ahead and do that. So first we would make a profile page. So let's go ahead and do that in our Fortify project. So let's just grab this from the last video. It's very similar to this with the password and the email here. And let's go ahead and duplicate the Dashboard, okay?
It's very similar to this with the password and the email here. And let's go ahead and duplicate the dashboard, okay? Or it doesn't matter actually, I'm just going to replace it with this anyways. So let's name it profile.blade.php. Let's grab this. And we are logged in, so let's change it to a app layout. That should have changed this closing tag, okay? And we have the errors here. And we have the session status. But the session status actually has a specific status here that we have to check for.
And we have the session status. But the session status actually has a specific status here that we have to check for. And that is profile_information_updated. And then in here we can just say that. So profile_info_updated has been updated, or whatever you want. You can also put this in the translations files and just put a key for this and then have multiple languages for that. Okay, so there's no option to put it in our FortifyServiceProvider like we've been doing. So we have to do it manually in our routes file. So let's add a new one for profile.
Adding Profile Route1:47
So we have to do it manually in our routes file. So let's add a new one for profile. I should make a route group here, but I'm just duplicating what we currently have. And this is profile. So let's replace all of those, okay? And now let's go back to our profile and update this. So the endpoint, let's take a look at our routes again. It's these two ones right here. So profile information and for password, it's password, user password, and they are PUT requests.
Wiring Profile Update Form2:18
So profile information and for password, it's password, userPassword, and they are PUT requests. So let's go ahead and grab this. I believe there's a route name for this too. But like I said, I'll just stick to the endpoint name. Like we've been doing, it's a PUT request. So it's a method put. And the endpoint is this, okay? And we don't need this token. And this is the userEmail.
And we don't need this token. And this is the user's email. So let's grab that from the logged in user. So let's change this off user email. And I'm going to duplicate this and add one for the name as well. And let's take autofocus off the email because I want it on the name. Okay, let's change these to name. Okay, this should be text. This should be name. I'm going to remove password here because we're going to do that separately.
This should be name. I'm going to remove password here because we're going to do that separately. And it's a separate route for that. So let's remove these. And let's say updateProfile here. Okay. Let's also add a link in our main layout here. So let's put another one here, or let's put it above logout. And it's a route. And I believe I need a profile.
And it's a route. And I believe I need a Profile. Okay, Profile. And it's a Profile here. Okay, so let's see if everything works. There's a Profile. And this information is populated. So now if I update this, this should work. And it does. Cool.
And it does. Cool. Let me refresh to make sure it did work. And it did. Now, in the Jetstream videos, I showed you how you can modify this and add new fields. You would just make use of the actions. So actions fortify and update the User information. And you can add any new fields here. Actually, let's check if the validation works. So let's say I don't put anything in here, and the messages are not showing.
Fixing Validation Errors4:34
Actually, let's check if the validation works. So let's say I don't put anything in here, and the messages are not showing. But if I refresh, the user's information still shows. So I think the only change I have to make is change validateWithBag to just validate. So validateWithBag allows you to have a named error bag, which we don't need in this case, because we only have one form. So let's just change this to validate. And hopefully the errors show now. So let's try that again. Let me refresh.
So let's try that again. Let me refresh. Let's remove this. And there it is. Cool. Now, if you look at the action, you'll see that there's a method for updating a verified User as well. So if you remember a few videos ago, we took a look at the feature that allowed us to verify email. And if we're changing our email here, then we have to verify the new email.
Building Password Update Page5:53
And we can verify that email address here. And there is the page. Cool. With the new email address. Now, let's do the same for updating our password. And it's on the same form in Jetstream, but I'm just going to separate it for demo purposes. So let's go ahead and make another route. Let's go to our routes file. Let's call this one password or passwordUpdate, whatever you want. And it's going to change it to password.
Let's call this one password or password update, whatever you want. And it's going to change it to password. Okay. Let's go ahead and duplicate this. Name it password.blade.php. And I think I forgot to change this name. Yeah, let's change it to profile. And let's change this one to update password. Okay. And for this, the session status is password updated.
Okay. And for this, the session status is password updated. So let's change this password updated. Oops, I already have that there. And let's just change this text to password has been updated. Okay. And the endpoint is user/password. So let's change this. It's a PUT request as well. And we just need the two password fields.
It's a PUT request as well. And we just need the two password fields. So let me grab that from the resetPassword view. So we just need these two password fields. Okay. Let's paste it in. Let's say updatePassword. Let's add that link to our app.blade.php. So let's put it right underneath. I need a password.
So let's put it right underneath. I need a password. Okay. Or updatePassword. And let's see if this works. So back to our app. Sorry, it's this one. password or updatePassword. View password not found. And I named it incorrectly.
Debugging Password Update8:03
View password not found. And I named it incorrectly. Okay, try again. Let's try the validation. So unmatching passwords, undefined index, currentPassword. That's because this has to be currentPassword. So let's change that. currentPassword. Actually, that should still be password. And there's two.
Okay. And that did not show up. Oh, yeah. So same thing. I have to change the action here and just say validate. Sorry, it's up here. UpdateUserPassword. And we don't need the bag. We just need it to validate. Okay.
And now hopefully this works. And it looks like it does. There is the success message. And let's verify that that worked. Let me just grab the user information, log out, log in again. And with that new password I just made, and it looks like it works.
