title
Laravel From Scratch [Part 9] - User Authentication

description
In this video we will add user authentication. We also need to add a user_id column in the posts table in the database. We will implement full login and register functionality CODE: Complete Code For This Series https://github.com/bradtraversy/lsapp 10 PROJECT LARAVEL COURSE: Please use affiliate link below https://www.eduonix.com/affiliates/id/16-10485 50% OFF: Use special code "traversy" SUPPORT: We spend massive amounts of time creating these free videos, please donate to show your support: http://www.paypal.me/traversymedia http://www.patreon.com/traversymedia FOLLOW TRAVERSY MEDIA: http://www.facebook.com/traversymedia http://www.twitter.com/traversymedia http://www.linkedin.com/in/bradtraversy

detail
{'title': 'Laravel From Scratch [Part 9] - User Authentication', 'heatmap': [{'end': 242.422, 'start': 201.011, 'weight': 0.788}, {'end': 374.397, 'start': 359.757, 'weight': 0.846}, {'end': 612.548, 'start': 601.698, 'weight': 1}, {'end': 922.456, 'start': 901.325, 'weight': 0.765}], 'summary': "In the video tutorial 'laravel from scratch [part 9] - user authentication,' the chapters cover setting up authentication in laravel, including enabling authentication with an artisan command, creating user models and controllers, generating a layout with bootstrap for login and registration forms, adding a navbar and csrf token, addressing missing links and margin issues, modifying elements, changing the default home controller to a dashboard controller, adding a user id field to the posts table using a database migration, and associating user ids with posts in a web application.", 'chapters': [{'end': 121.2, 'segs': [{'end': 102.826, 'src': 'embed', 'start': 20.583, 'weight': 0, 'content': [{'end': 26.665, 'text': 'Now, if you wanted to add extra fields here, you could have added them here before and then ran the migration,', 'start': 20.583, 'duration': 6.082}, {'end': 28.085, 'text': 'or you can even add them now and run it.', 'start': 26.665, 'duration': 1.42}, {'end': 33.348, 'text': "But this is fine for what we're going to do, name, email, password, ID.", 'start': 29.566, 'duration': 3.782}, {'end': 38.551, 'text': "So what we're going to do is we're going to enable authentication.", 'start': 34.249, 'duration': 4.302}, {'end': 40.372, 'text': "We already have the user's table.", 'start': 39.072, 'duration': 1.3}, {'end': 44.775, 'text': 'So to enable authentication, we can just run an artisan command.', 'start': 40.473, 'duration': 4.302}, {'end': 48.397, 'text': "So let's go ahead and do, let's go to our terminal here.", 'start': 45.636, 'duration': 2.761}, {'end': 50.058, 'text': 'And all we have to do is PHP.', 'start': 49.218, 'duration': 0.84}, {'end': 56.462, 'text': 'artisan make off.', 'start': 52.961, 'duration': 3.501}, {'end': 65.206, 'text': 'okay, this one command is going to basically enable all of the the user model, all the controllers, the auth controllers here,', 'start': 56.462, 'duration': 8.744}, {'end': 70.768, 'text': "and we're going to have a login system that's going to just work right off the bat, which is just friggin awesome.", 'start': 65.206, 'duration': 5.562}, {'end': 80.001, 'text': "so let's run that Now this here when you create authentication, it creates a layout for you.", 'start': 70.768, 'duration': 9.233}, {'end': 86.302, 'text': 'And the layout is very similar to what we have now, which is just a navbar.', 'start': 80.741, 'duration': 5.561}, {'end': 91.464, 'text': 'It uses Bootstrap, and it creates a form for your registration and all that.', 'start': 87.243, 'duration': 4.221}, {'end': 95.104, 'text': 'Well, actually, those are views, but the layout it extends from.', 'start': 91.964, 'duration': 3.14}, {'end': 102.826, 'text': "So if we go to Resources, Views, it's going to replace this app.blade.php file.", 'start': 95.244, 'duration': 7.582}], 'summary': 'Enabling authentication using artisan command to create login system and layout.', 'duration': 82.243, 'max_score': 20.583, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk20583.jpg'}], 'start': 0.598, 'title': 'Laravel authentication setup', 'summary': 'Discusses setting up authentication and access control in laravel, including enabling authentication with an artisan command, creating user models and controllers, and generating a layout with bootstrap for login and registration forms.', 'chapters': [{'end': 121.2, 'start': 0.598, 'title': 'Laravel authentication setup', 'summary': 'Discusses setting up authentication and access control in laravel, including enabling authentication with an artisan command, creating user models and controllers, and generating a layout with bootstrap for login and registration forms.', 'duration': 120.602, 'highlights': ["Enabling authentication with Laravel's artisan command creates user models and controllers, and a login system that works seamlessly. Running the 'PHP artisan make off' command enables authentication, creating user models, controllers, and a functional login system.", 'The authentication setup generates a layout using Bootstrap, including views for registration and login forms. The authentication setup creates a layout that uses Bootstrap and includes views for registration and login forms, streamlining the development process.', 'Additional fields can be added to the users table in the database to customize user data. The users table in the database can be customized by adding extra fields before or after running the migration, providing flexibility in user data management.']}], 'duration': 120.602, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk598.jpg', 'highlights': ["Running the 'PHP artisan make off' command enables authentication, creating user models, controllers, and a functional login system.", 'The authentication setup creates a layout that uses Bootstrap and includes views for registration and login forms, streamlining the development process.', 'The users table in the database can be customized by adding extra fields before or after running the migration, providing flexibility in user data management.']}, {'end': 709.312, 'segs': [{'end': 190.541, 'src': 'embed', 'start': 124.13, 'weight': 0, 'content': [{'end': 133.216, 'text': "So now if we go and let's close this and look at our app.blade file, and it added a bunch of stuff for us and some of this stuff we can actually use.", 'start': 124.13, 'duration': 9.086}, {'end': 139.6, 'text': 'So for instance, it added this CSRF token, which we would have had to add later anyways for security reasons.', 'start': 133.316, 'duration': 6.284}, {'end': 141.582, 'text': 'It gives us a navbar.', 'start': 140.441, 'duration': 1.141}, {'end': 144.95, 'text': 'And if we look down here, it has all kinds of logic.', 'start': 142.608, 'duration': 2.342}, {'end': 150.875, 'text': "So on the right side of the nav bar, it's going to have a login and register link.", 'start': 145.931, 'duration': 4.944}, {'end': 154.998, 'text': "And it's going to check to see if we're guests, if we're not logged in.", 'start': 151.035, 'duration': 3.963}, {'end': 155.999, 'text': "It'll display that.", 'start': 155.138, 'duration': 0.861}, {'end': 162.504, 'text': "Else, then it's going to display a dropdown with our username and also a logout function.", 'start': 156.74, 'duration': 5.764}, {'end': 167.729, 'text': "So let's go ahead and save it and go back.", 'start': 163.525, 'duration': 4.204}, {'end': 172.973, 'text': 'Reload, and this is the navbar that is included.', 'start': 169.63, 'duration': 3.343}, {'end': 176.955, 'text': 'it has a login and register link and these pages are going to work.', 'start': 172.973, 'duration': 3.982}, {'end': 182.397, 'text': 'just by enabling the authentication that we did, we should be able to register and all that.', 'start': 176.955, 'duration': 5.442}, {'end': 183.938, 'text': "but let's fix the navbar.", 'start': 182.397, 'duration': 1.541}, {'end': 184.818, 'text': "there's some issues here.", 'start': 183.938, 'duration': 0.88}, {'end': 188, 'text': "we don't have our pages, our links here anymore.", 'start': 184.818, 'duration': 3.182}, {'end': 190.541, 'text': 'you also see we have some margin under it.', 'start': 188, 'duration': 2.541}], 'summary': 'The app.blade file added security measures and a functioning navbar with login, register, and user-specific features.', 'duration': 66.411, 'max_score': 124.13, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk124130.jpg'}, {'end': 242.422, 'src': 'heatmap', 'start': 201.011, 'weight': 0.788, 'content': [{'end': 217.075, 'text': "so what I'm going to do is copy or cut the whole navbar out and we're going to go to our navbar include and let's just go under all this and paste it in.", 'start': 201.011, 'duration': 16.064}, {'end': 222.918, 'text': "okay, and then we'll take what we need from our old one, which is this ul here with all the pages.", 'start': 217.075, 'duration': 5.843}, {'end': 234.873, 'text': "so we'll copy that and we're going to put it right above this ul that has the navbar right, okay,", 'start': 222.918, 'duration': 11.955}, {'end': 242.422, 'text': "and then we're also going to remove the static navbar static top.", 'start': 234.873, 'duration': 7.549}], 'summary': 'Copying and pasting the navbar, reorganizing the code', 'duration': 41.411, 'max_score': 201.011, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk201011.jpg'}, {'end': 383.363, 'src': 'heatmap', 'start': 359.757, 'weight': 0.846, 'content': [{'end': 369.541, 'text': "Email address, I'll just do brad at gmail, password.", 'start': 359.757, 'duration': 9.784}, {'end': 374.397, 'text': 'and register.', 'start': 373.656, 'duration': 0.741}, {'end': 383.363, 'text': 'okay, so what it does by default is it registers us, it signs, it logs us in and it brings us to slash home.', 'start': 374.397, 'duration': 8.966}], 'summary': "Registers user with email 'brad@gmail', logs in, and brings to home page.", 'duration': 23.606, 'max_score': 359.757, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk359757.jpg'}, {'end': 396.151, 'src': 'embed', 'start': 374.397, 'weight': 4, 'content': [{'end': 383.363, 'text': 'okay, so what it does by default is it registers us, it signs, it logs us in and it brings us to slash home.', 'start': 374.397, 'duration': 8.966}, {'end': 387.505, 'text': 'and if we look over here in our controllers, it gives us a home controller.', 'start': 383.363, 'duration': 4.142}, {'end': 390.507, 'text': "now, personally, i don't like the name home.", 'start': 387.505, 'duration': 3.002}, {'end': 396.151, 'text': "i would rather this be dashboard, because that that tells us that it's actually a back end.", 'start': 390.507, 'duration': 5.644}], 'summary': "The system registers, signs in, and directs to '/home', but the controller name 'home' is preferred to be 'dashboard' for clarity.", 'duration': 21.754, 'max_score': 374.397, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk374397.jpg'}, {'end': 639.178, 'src': 'heatmap', 'start': 601.698, 'weight': 1, 'content': [{'end': 604.36, 'text': 'All right, good.', 'start': 601.698, 'duration': 2.662}, {'end': 610.126, 'text': 'Now, when we create a post, I want to insert the user ID as a field.', 'start': 605.602, 'duration': 4.524}, {'end': 612.548, 'text': "Now, if we go to our post table, we don't have that here.", 'start': 610.166, 'duration': 2.382}, {'end': 616.932, 'text': "OK, we have title body, but we don't have any area for user ID.", 'start': 613.209, 'duration': 3.723}, {'end': 621.096, 'text': "So what we'll do is create a migration that's going to add that to this table.", 'start': 617.052, 'duration': 4.044}, {'end': 626.001, 'text': "So let's go to our command line or terminal.", 'start': 621.837, 'duration': 4.164}, {'end': 639.178, 'text': "and we're going to do php artisan and we want to do make migration and you want to give this a very descriptive name.", 'start': 628.348, 'duration': 10.83}], 'summary': 'Task: add user id field to post table via migration', 'duration': 37.48, 'max_score': 601.698, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk601698.jpg'}, {'end': 654.55, 'src': 'embed', 'start': 617.052, 'weight': 3, 'content': [{'end': 621.096, 'text': "So what we'll do is create a migration that's going to add that to this table.", 'start': 617.052, 'duration': 4.044}, {'end': 626.001, 'text': "So let's go to our command line or terminal.", 'start': 621.837, 'duration': 4.164}, {'end': 639.178, 'text': "and we're going to do php artisan and we want to do make migration and you want to give this a very descriptive name.", 'start': 628.348, 'duration': 10.83}, {'end': 647.306, 'text': "so we'll say add underscore user id to posts.", 'start': 639.178, 'duration': 8.128}, {'end': 649.447, 'text': "we'll just do add user ID to posts.", 'start': 647.306, 'duration': 2.141}, {'end': 652.349, 'text': "Okay, so let's go ahead and run that.", 'start': 650.467, 'duration': 1.882}, {'end': 654.55, 'text': 'Created migration.', 'start': 653.529, 'duration': 1.021}], 'summary': 'Created migration to add user id to posts.', 'duration': 37.498, 'max_score': 617.052, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk617052.jpg'}], 'start': 124.13, 'title': 'Navbar and database migration in laravel', 'summary': 'Covers adding a navbar and csrf token in the app.blade file, enabling authentication for login and register links, addressing missing links and margin issues in the navbar, updating the navbar layout, modifying elements, changing the default home controller to a dashboard controller, and adding a user id field to the posts table using a database migration.', 'chapters': [{'end': 190.541, 'start': 124.13, 'title': 'Adding navbar and csrf token in laravel', 'summary': 'Covers the addition of a navbar and csrf token in the app.blade file, enabling authentication for login and register links, and addressing issues with missing links and margin in the navbar.', 'duration': 66.411, 'highlights': ['The app.blade file added a CSRF token for security reasons and a navbar with logic for displaying login/register links and username/logout function.', 'Enabling authentication allows registration and login functionality for the login and register links.', 'Issues with missing links and margin in the navbar need to be fixed.']}, {'end': 709.312, 'start': 190.541, 'title': 'Updating navbar and database migration', 'summary': 'Covers updating the navbar layout by moving and modifying elements, changing the default home controller to a dashboard controller, and adding a user id field to the posts table using a database migration.', 'duration': 518.771, 'highlights': ["Changing the default home controller to a dashboard controller The instructor demonstrates how to change all instances of 'home' to 'dashboard' in the controller, views, and routes, providing a clearer indication of the back end. This change is a personal preference but can enhance clarity in the application.", 'Updating the navbar layout by moving and modifying elements The instructor guides the process of moving the navbar to a separate include file, making changes to the navbar style, and ensuring the inclusion of necessary components such as the messages include and the create post link, providing a clear and organized user interface.', 'Adding a user ID field to the posts table using a database migration The process of creating a migration to add a user ID field to the posts table is demonstrated, emphasizing the use of a descriptive migration name and the execution of the migration to modify the database structure.']}], 'duration': 585.182, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk124130.jpg', 'highlights': ['The app.blade file added a CSRF token for security and a navbar with logic for displaying login/register links and username/logout function.', 'Enabling authentication allows registration and login functionality for the login and register links.', 'Updating the navbar layout by moving and modifying elements to provide a clear and organized user interface.', 'Adding a user ID field to the posts table using a database migration, emphasizing the use of a descriptive migration name and the execution of the migration to modify the database structure.', 'Changing the default home controller to a dashboard controller, providing a clearer indication of the back end and enhancing clarity in the application.', 'Issues with missing links and margin in the navbar need to be fixed.']}, {'end': 1001.773, 'segs': [{'end': 769.622, 'src': 'embed', 'start': 738.549, 'weight': 0, 'content': [{'end': 746.193, 'text': "so let's go to our terminal and we're going to do PHP artisan migrate.", 'start': 738.549, 'duration': 7.644}, {'end': 751.695, 'text': "OK, now let's go look at our database to reload this.", 'start': 747.774, 'duration': 3.921}, {'end': 756.297, 'text': "And now you'll see that our posts have a user ID column.", 'start': 752.896, 'duration': 3.401}, {'end': 762.139, 'text': "OK, so we didn't have to go into phpMyAdmin or the SQL shell and do it ourselves.", 'start': 757.017, 'duration': 5.122}, {'end': 763.82, 'text': 'We can just run a migration.', 'start': 762.519, 'duration': 1.301}, {'end': 769.622, 'text': 'And if we wanted to undo that, we could just do phpArtisan migrate rollback.', 'start': 764.16, 'duration': 5.462}], 'summary': 'Using php artisan migrate to add user id column to posts without manual sql commands.', 'duration': 31.073, 'max_score': 738.549, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk738549.jpg'}, {'end': 994.991, 'src': 'heatmap', 'start': 901.325, 'weight': 2, 'content': [{'end': 906.989, 'text': "let's try that, alright.", 'start': 901.325, 'duration': 5.664}, {'end': 910.811, 'text': 'so now, if we create a post, see where we at, we have 123.', 'start': 906.989, 'duration': 3.822}, {'end': 922.456, 'text': "so let's create for Whoa?", 'start': 910.811, 'duration': 11.645}, {'end': 923.217, 'text': "where's the editor?", 'start': 922.456, 'duration': 0.761}, {'end': 928.941, 'text': 'Wait a second.', 'start': 928.261, 'duration': 0.68}, {'end': 933.205, 'text': 'What happened to the editor? Oh, the layout.', 'start': 928.981, 'duration': 4.224}, {'end': 934.766, 'text': 'We got rid of it.', 'start': 933.965, 'duration': 0.801}, {'end': 938.729, 'text': 'Shoot So we got to go back to our app.layout.', 'start': 936.447, 'duration': 2.282}, {'end': 941.28, 'text': "or app.blade, I'm sorry.", 'start': 940.02, 'duration': 1.26}, {'end': 945.481, 'text': "And let's see, we just need to put that JavaScript back.", 'start': 942.501, 'duration': 2.98}, {'end': 952.103, 'text': "So let's go back to the documentation for laravel-ck-editor.", 'start': 945.601, 'duration': 6.502}, {'end': 956.264, 'text': 'And we just need this.', 'start': 952.123, 'duration': 4.141}, {'end': 960.745, 'text': 'Okay, put that right down here.', 'start': 956.284, 'duration': 4.461}, {'end': 963.306, 'text': 'And save.', 'start': 962.546, 'duration': 0.76}, {'end': 967.067, 'text': 'And that should give us the editor back, good.', 'start': 963.326, 'duration': 3.741}, {'end': 986.168, 'text': 'so post four submit and now if we go and look in our database and go to our post table You can see that post four got user ID one.', 'start': 968.869, 'duration': 17.299}, {'end': 990.99, 'text': 'So if we were logged in with someone with the user ID of two, then two would have got put there.', 'start': 987.149, 'duration': 3.841}, {'end': 994.991, 'text': 'So that way we can track what posts belong to what user.', 'start': 991.55, 'duration': 3.441}], 'summary': 'Resolved issue with editor, restored functionality for post creation and user tracking.', 'duration': 134.401, 'max_score': 901.325, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk901325.jpg'}], 'start': 710.493, 'title': 'Database migration and user id association', 'summary': "Explains database migration in laravel, covering adding and rolling back table columns, using artisan commands, and associating user ids with posts in a web application. it also discusses adding the currently logged-in user's id to the post, creating a dashboard link in the navbar, updating the app layout to include a javascript code for the editor, and tracking posts by user id in the database.", 'chapters': [{'end': 834.012, 'start': 710.493, 'title': 'Database migration and user id association', 'summary': 'Explains database migration in laravel, including adding and rolling back table columns, using artisan commands, and associating user ids with posts in a web application.', 'duration': 123.519, 'highlights': ['Running a migration in Laravel adds a new column to a table, eliminating the need for manual database manipulation.', 'Rolling back a migration in Laravel involves deleting the added column using artisan commands, providing a streamlined way to undo changes.', "Associating user IDs with posts in a web application involves accessing the authenticated user's ID and adding it to the post data in the controller."]}, {'end': 1001.773, 'start': 834.012, 'title': 'Adding user id to posts', 'summary': "Discusses adding the currently logged-in user's id to the post and creating a dashboard link in the navbar, highlighting the process of updating the app layout to include a javascript code for the editor and tracking posts by user id in the database.", 'duration': 167.761, 'highlights': ["The user's ID is added to the post, allowing tracking of posts by user ID in the database.", 'A dashboard link is created in the navbar to provide easy access to the dashboard.', 'The app layout is updated to include JavaScript code for the editor, ensuring its functionality.', "The process of adding the currently logged-in user's ID to the post is discussed as a key point in the chapter."]}], 'duration': 291.28, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ORus3-By4lk/pics/ORus3-By4lk710493.jpg', 'highlights': ['Running a migration in Laravel adds a new column to a table, eliminating the need for manual database manipulation.', 'Rolling back a migration in Laravel involves deleting the added column using artisan commands, providing a streamlined way to undo changes.', "The process of adding the currently logged-in user's ID to the post is discussed as a key point in the chapter.", "The user's ID is added to the post, allowing tracking of posts by user ID in the database.", 'A dashboard link is created in the navbar to provide easy access to the dashboard.', 'The app layout is updated to include JavaScript code for the editor, ensuring its functionality.']}], 'highlights': ["Running the 'PHP artisan make off' command enables authentication, creating user models, controllers, and a functional login system.", 'The authentication setup creates a layout that uses Bootstrap and includes views for registration and login forms, streamlining the development process.', 'The users table in the database can be customized by adding extra fields before or after running the migration, providing flexibility in user data management.', 'The app.blade file added a CSRF token for security and a navbar with logic for displaying login/register links and username/logout function.', 'Enabling authentication allows registration and login functionality for the login and register links.', 'Updating the navbar layout by moving and modifying elements to provide a clear and organized user interface.', 'Adding a user ID field to the posts table using a database migration, emphasizing the use of a descriptive migration name and the execution of the migration to modify the database structure.', 'Changing the default home controller to a dashboard controller, providing a clearer indication of the back end and enhancing clarity in the application.', 'Issues with missing links and margin in the navbar need to be fixed.', 'Running a migration in Laravel adds a new column to a table, eliminating the need for manual database manipulation.', 'Rolling back a migration in Laravel involves deleting the added column using artisan commands, providing a streamlined way to undo changes.', "The process of adding the currently logged-in user's ID to the post is discussed as a key point in the chapter.", "The user's ID is added to the post, allowing tracking of posts by user ID in the database.", 'A dashboard link is created in the navbar to provide easy access to the dashboard.', 'The app layout is updated to include JavaScript code for the editor, ensuring its functionality.']}