hey what's up guys welcome back to our blog and welcome to this blog so this is the part 14 of our laravel for beginners tutorial and in this blog we're going to discuss about user authentication but as a sort of review in the previous tutorials we have worked with our create read update delete functionality for our project so as I've said in this blog we're going to discuss user authentication so as you can see we have here the land in register functions and if tried to go to our database we can see we have already created or populated our users table with the attributes ID name email email verified password token and the created and updated fields or attributes so let's go back to our code editor and try to add more features to our project and add the user authentication and perhaps the user access control to our project so let's go back to our code editor and let's try to see the views in the views we have already this file right so as you can see we have different options and different menus the home services blog the about and of course we have added the login and register links so that we will be able to log in and of course we will be able to register it to our project and for now let's just copy this because we're going to overwrite this file so let's do that by creating a new file as a sort of back up and let's start to open up our command line so that we'll be able to create the authentication or user authentication for our project so in here let's just type in PHP artisan and then make Colin and then the keyword oath and then let's just try to wait for a few seconds to enable the so as you can see we have here a problem come and make both is not defined so I think we have Oh so instead of using the artisan make oath so I think we need to run the command PHP artisan instead and then you I and then oath so this will enable the authentication or user authentication for our project and we have here a prompt that says the oath plug-in that laid that page review already exist do you want to replace it so for now let's just say yes because you want them to be replaced with a new version of the login dot PHP the way that page B email that PHP and I'm just gonna answer yes to this prompt verify so this will again override our old files so authentication scaffolding generated successfully so if we try to run our project right now let's say refresh ok so as you can see we have already alright or every than our our old files and as you can see we don't have any additional options here for our blog services and adding the post so we need to add that in our app that laid that PHP files so as you can see we have the backup for our app that blade that page we file and we have here the new one okay so all we have to do is just you can just copy the for example the link from here so starting from here to the the first navigation item for our home and then paste it here there you go and of course we need to add also the navigation for adding a post so you L left side of our navigation okay so we have here the option to add post and of course guys we can make the navigation bar instead of light you can say inverse just gonna remove this so navigation bar inverse and then save this one and let's go back to our browser and then refresh so as you can see we have added all the options to add post we also have the home services blog about and of course the login and register pages and as you can see we need to fix this display right here because I think it's not indented so let's go back to our code editor and try to modify that so index for our content so we don't have here the div container so we need to add that in our up that way that PHP file okay so we have here the content yielding of content but we need to add the container class or it could inner div with a class on container okay so this should solve the problem of the intention or the margin left for our project refresh so as you can see now the content is indented and if we try to go to register we can already we can already register here by using our names of our example Tom saw and an email let's just say Tom at gmail.com and then password okay and then register and as you can see we have redirected and so our home and prompted that we are now back in so you can see we have enabled the user authentication and the laravel takes care of all the intricacies of using the user authentication within our project okay now so we can close this and let's try to edit our home that played that PHP so instead of just showing your now login let's just say we can add a post here so that will be post and then click yeah great and a host and then we're just going to add a class for our button or link BT and BT and primary and let's just say here your love posts let me say this try to preview and then refresh so we have here the updated dashboard or home page then we can just create a post but if you try to do up in our database post suppose because we want to add the ID of the user that has posted the certain post so we need to make immigration for that at the attribute ID of our user so now let's add the migration for adding our user ID into our database table so in here you need to run the command aah we make HP artisan then make and then migration and then the name of our migration is add user ID to post ok so PHP artisan make Colin in the migration add user ID to post and it says it created the migration so if we try to go back to our file and then under database in the migrations we now have the migration add user ID to post ok so if you try to run our migration right now that nothing will happen because we don't have any logic inside the app and the down function so in order for us to add the ID so the user table in our database we need to have some logic here and also run the migration so inside here we need to say table and then integer because the value of the user ID is of integer type so user and then underscore ID and semicolon and of course whenever we want to roll back the changes that we made in our migrations we can just say table and drop column and then specifying the column user ID so okay so after that one save this and then let's just say PHP artisan migrate so migrating user ID post and it says migrated so let's track our page we my admin so inside here in our database we can see we have already the user underscore ID and for now let's just say it belongs to user 1 this particular post and also this one it belongs to the user 1 so it just it belongs to someone okay so now let's try to edit the controller for our post because whenever we need whenever we add a certain post we want the user ID or grab the user ID and add that along with the other information of the post so let's just go to http and then controllers and then post controllers okay so oh so inside our store function we just need to have the user ID or pass in the is ready so here post and then user ID equals and this time we're not gonna use the request because the user ID doesn't come from the user our I mean doesn't come from request it comes from the user both so it should say both and then user and then we're just going to have or you grab the ID hey and then save so here refresh at post then certain title of a pose new body of a pose and then submit so we have now the certain title of a post and we try to check the third post we can see that the user ID has been populated by value of 1 which means that this particular post belongs to the user with the ID 1 so I think that's all there is to it for this tutorial in the next blog we're going to discuss about access control for our post so see you in the next blog thanks
hey what's up guys welcome back to our blog and welcome to this blog so this is the part 14 of our laravel for beginners tutorial and in this blog we're going to discuss about user authentication but as a sort of review in the previous tutorials we have worked with our create read update delete functionality for our project so as I've said in this blog we're going to discuss user authentication so as you can see we have here the land in register functions and if tried to go to our database we can see we have already created or populated our users table with the attributes ID name email email verified password token and the created and updated fields or attributes so let's go back to our code editor and try to add more features to our project and add the user authentication and perhaps the user access control to our project so let's go back to our code editor and let's try to see the views in the views we have already this file right so as you can see we have different options and different menus the home services blog the about and of course we have added the login and register links so that we will be able to log in and of course we will be able to register it to our project and for now let's just copy this because we're going to overwrite this file so let's do that by creating a new file as a sort of back up and let's start to open up our command line so that we'll be able to create the authentication or user authentication for our project so in here let's just type in PHP artisan and then make Colin and then the keyword oath and then let's just try to wait for a few seconds to enable the so as you can see we have here a problem come and make both is not defined so I think we have Oh so instead of using the artisan make oath so I think we need to run the command PHP artisan instead and then you I and then oath so this will enable the authentication or user authentication for our project and we have here a prompt that says the oath plug-in that laid that page review already exist do you want to replace it so for now let's just say yes because you want them to be replaced with a new version of the login dot PHP the way that page B email that PHP and I'm just gonna answer yes to this prompt verify so this will again override our old files so authentication scaffolding generated successfully so if we try to run our project right now let's say refresh ok so as you can see we have already alright or every than our our old files and as you can see we don't have any additional options here for our blog services and adding the post so we need to add that in our app that laid that PHP files so as you can see we have the backup for our app that blade that page we file and we have here the new one okay so all we have to do is just you can just copy the for example the link from here so starting from here to the the first navigation item for our home and then paste it here there you go and of course we need to add also the navigation for adding a post so you L left side of our navigation okay so we have here the option to add post and of course guys we can make the navigation bar instead of light you can say inverse just gonna remove this so navigation bar inverse and then save this one and let's go back to our browser and then refresh so as you can see we have added all the options to add post we also have the home services blog about and of course the login and register pages and as you can see we need to fix this display right here because I think it's not indented so let's go back to our code editor and try to modify that so index for our content so we don't have here the div container so we need to add that in our up that way that PHP file okay so we have here the content yielding of content but we need to add the container class or it could inner div with a class on container okay so this should solve the problem of the intention or the margin left for our project refresh so as you can see now the content is indented and if we try to go to register we can already we can already register here by using our names of our example Tom saw and an email let's just say Tom at gmail.com and then password okay and then register and as you can see we have redirected and so our home and prompted that we are now back in so you can see we have enabled the user authentication and the laravel takes care of all the intricacies of using the user authentication within our project okay now so we can close this and let's try to edit our home that played that PHP so instead of just showing your now login let's just say we can add a post here so that will be post and then click yeah great and a host and then we're just going to add a class for our button or link BT and BT and primary and let's just say here your love posts let me say this try to preview and then refresh so we have here the updated dashboard or home page then we can just create a post but if you try to do up in our database post suppose because we want to add the ID of the user that has posted the certain post so we need to make immigration for that at the attribute ID of our user so now let's add the migration for adding our user ID into our database table so in here you need to run the command aah we make HP artisan then make and then migration and then the name of our migration is add user ID to post ok so PHP artisan make Colin in the migration add user ID to post and it says it created the migration so if we try to go back to our file and then under database in the migrations we now have the migration add user ID to post ok so if you try to run our migration right now that nothing will happen because we don't have any logic inside the app and the down function so in order for us to add the ID so the user table in our database we need to have some logic here and also run the migration so inside here we need to say table and then integer because the value of the user ID is of integer type so user and then underscore ID and semicolon and of course whenever we want to roll back the changes that we made in our migrations we can just say table and drop column and then specifying the column user ID so okay so after that one save this and then let's just say PHP artisan migrate so migrating user ID post and it says migrated so let's track our page we my admin so inside here in our database we can see we have already the user underscore ID and for now let's just say it belongs to user 1 this particular post and also this one it belongs to the user 1 so it just it belongs to someone okay so now let's try to edit the controller for our post because whenever we need whenever we add a certain post we want the user ID or grab the user ID and add that along with the other information of the post so let's just go to http and then controllers and then post controllers okay so oh so inside our store function we just need to have the user ID or pass in the is ready so here post and then user ID equals and this time we're not gonna use the request because the user ID doesn't come from the user our I mean doesn't come from request it comes from the user both so it should say both and then user and then we're just going to have or you grab the ID hey and then save so here refresh at post then certain title of a pose new body of a pose and then submit so we have now the certain title of a post and we try to check the third post we can see that the user ID has been populated by value of 1 which means that this particular post belongs to the user with the ID 1 so I think that's all there is to it for this tutorial in the next blog we're going to discuss about access control for our post so see you in the next blog thanks
Post a Comment