11. Creating the login form


We've tested the login functionality but at the moment we haven't actually built the login page
so let's go ahead and do that hook it up and we can move on to something a little bit more interesting. The first thing that we'll do is come over to our base layout and just hook this up to auth slash login so at least we can go ahead and click on it and at the moment we don't see anything because we haven't got a view for this so why don't we just copy over the register view
so let's head over to register here copy this over we'll create a new file in here login.blade.php paste this in and we'll just switch this up so we'll just say log in and of course that's going to go through to slash login which we've already tested and we're not going to need the user's name here we're just going to need their email address
their password and a button that's going to sign them in so if we come over now and give this a refresh still not working because over in our login controller we haven't returned a view so let's go ahead and do that now and hook that up to auth and login give that a refresh and there we go we should be able to sign in. Now what I tend to do is just create very simple tests for
every page that we build just to make sure that it is okay so let's go ahead and just do that really quickly now so let's just say it shows the login page you can call that whatever you like and we can just create a really simple higher order test for this and just say get forward slash auth forward slash login and then we could just use either assert status or we could just say
something like assert okay so let's just run pest here and sure enough that passes that just means that if anything goes wrong on this page here then it's going to tell us so let's just check out our database and see which users we have registered there are none at the moment because of course we've just been testing and not actually doing anything so let's go ahead and just go
through the whole flow of registering a user being signed in which we can see here we don't have the logout functionality at the moment so let's go over to our application tab under cookies manually delete these and I'm just going to go ahead and authenticate with that user really quickly and there we go we're also signed in great while we're here let's just implement the logout functionality
just so we've got it there and we can play around with it so over in app.blade.php let's head over to logout with this we're going to make this slightly different because if we implement this as a get route it's going to be vulnerable to cross-site request forgery attacks so instead what we're going to do is make this anchor a button we're going to wrap this in a form here
and let's go through to just logout that's the fortify route for logout the method here is going to be post this now means that we can bring in our cross-site request forgery token and we can switch this over to a button and of course that means we don't need our href so change that to button and that's literally just going to post through to logout and we should be able to sign out great
35 episodes4 hrs 19 mins


Pest is a PHP testing framework that brings beautifully simple syntax to your tests, without sacrificing on features. In this course, we'll get up and running with Pest in a Laravel project and write tests for a real-world application that we'll build along the way.

You'll learn how to set Pest up in a Laravel project, write tests with Pest's built-in assertions, generate code coverage, and more.

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


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