Laravel Basic Project For Beginners Step by Step

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is yamin and welcome to f tech knowledge so today we will learn how we can make a simple or basic website using laravel so there won't be anything critical or advanced in this tutorial series so if you are a beginner and if you want to create a simple or basic website using laravel then this is the best tutorial for you because i'll make it really easy and really simple to understand as much possible as i can i'll try my best so that everyone can understand it really clearly so before we start creating our project let me just uh tell you what we required to create a laravel project first of all you need to install xampp in your device just search for jam then you will see something like this and after you install xampp you need to make sure that you have composer installed in your device as well because composer is required for getting a laravel project and you also regard to have node.js installed as well and when you are installing node.js i'd always recommend you to use this one record for most user this version so once you have those three installed sam composer and node.js you are ready to create your laravel project so let me just close those three things so here you can see uh this is laravel.com this is the documentation page and here if you go down here you can see a command over here composer global required laravel slash installer now this command help us to install laravel globally in our device and after you install this or run this command in order to get the laval project all you have to do is that run a command call laravel new and your project name so first of all let's say we want to create our project in the new volume f let's say over here so over here we need to open a common prompt so we'll just see over here cmd then press enter and it will open a command prompt over here like this as you can see so i already have laravel installed globally but just to show you let me just copy this command and i paste over here and i'll press enter so the command is composer global required laravel slash installer and it will take around like uh five minutes at most to install since i already have installed that's why it didn't took long so once you run this command you will be able to get your laravel project anywhere on your device you can get laravel project in the new volume f d c anywhere you want okay so we will create the laravel project over here in the new volume f so in order to create the liable project the command is laravel new and the project name so let me open a common prompt here again cmd just right over here cmd and here i'm going to say laravel new and we need to mention our project name unless our project name will be basic laravel okay let's just say basic lara project and we press enter and it will create a laravel project for us it will take at most five minutes and there you go here you can see our laravel project is created and over here you can see a new folder which says basic lara project which we just created now i will open this project using sublime text so you can use visual studio or atom anything you want so i'll just open it i'll just click file then open folder then i'll go to new volume f and here you can see basic clara project select folder so uh here let me close this minimize it minimize it and here uh you can see basically our project if i go inside here you can see some folder and file over here which we just opened using sublime text as you can see app bootstrap so these are laravel project and if you want to run this project all you have to is that uh we need to go to the project directory which is basic clara project so for it you can just over here cd basic lara project and if you press enter here you can see we are currently in the basic lara project directory which means we are over here but you can also do one more thing that is you can just go to the folder location and open a command prompt here it will basically do the same thing so in order to run the project all you have to do is that you need to write over here php rt artisan serve and press enter and here you can see it is running so let me just copy this on inside the third bracket and we'll paste it in the browser and there you go this is the laravel project that we just created so let's go and right now setup our database for this project so for it uh first of all we need to open our xampp i haven't opened the exam so i'll just server here search for them then i'll go to xampp control panel and here we need to start the xampp apache and mysql let me just minimize it and here i'm just go to my exam over here i'll go to my phpmyadmin then okay here you may notice that uh my ipad this is on to 7.0.80 because over here you can see that my exam port number is eight zero if your sample number is different you need to have different port number okay i'm just mentioning it if someone get confused so here let's go and create a database so for it uh you need to click over here here you can see a new button option just click new and it will open something like this create database so here we are going to say let's say basic project and then we click over here create and here you can see a database is created called basic project so we are going to use this name in our dot inv file in our laravel project so let me just go to my sublime text and over here you will see a dot in the file we'll just go inside and here you can see db database basic lara project which is basically our folder name so instead of this we are going to say basic project which was our database name and then save it so right now our laravel project is connected to our this database okay so right now let's go and create registration and login for this project so for creating relation and login you need to write some comment over here which i write in the notepad here you can see so in order to create login and registration we need to write this five command so the first command is composer record laravel slash existing so let me just copy it and right now here you can see this con prompt is already running so we'll uh get another open another command prompt over here so we'll see over here cmd in the project directory so here you can see we are in the project directory and here we are going to paste the command which was composer required laravel slash jsteam so we'll press enter and it will install jsteam in our laravel project and here you can see that just installation is done so after it will go copy the second command which is php addition jsteam clone install install livewire so let me just copy it and i'll paste it over here and i'll press enter and it will take a few seconds so here you can see the second command is also done so after it we have two more command i mean three more command npm install and npm run dev so first we'll run this command npm install so here we are going to say npm install and then we'll press enter now this may take some time so here you can see npm install is also done so after it we have npm run dev so if i just copy it and if i just paste it over here or let's just say over here npm run dev it wasn't copied so let's press enter and here you can see uh it is running something but uh in order to run the command of php artisan mygate we need to stop this so in order to stop this we can just press over here ctrl c and uh it is asking terminate patch job will say yes and press enter so here uh what will happen if we run this command psp edition migrate and that is uh let me just go to my project and if i go in the project here we have a database folder over here you can see after config and inside database we have a migration folder and inside migration folder here you can see user table then password uh personal access session table so if we run this command ps4 edition mygate then it will migrate all those table uh in our database which is this one basic project so in the command prompt we are going to say php rt sun migrate let's press enter and here you can see migration is done so right now if i just refresh over here here you can see a few table over here we have user table name email id and we also have a few more table over here as well so right now here if we go to our laravel and if we now refresh over here you can see login and registration option and right now if we click register it will take us over here you can see name email password compound password and if you click login it will take us to the login page so we have the login and registration option properly so right now let's try to register so right now let's write a name over here yeah i mean let's give it um email which let's say yamin died of gmail.com and let's do a password on two three four five six seven eight on two three four five six seven eight and let's press enter and here you can see it took us to the dashboard over here so we are able to register and login over here so after login it will take us over here and hotend is that we want some option over here so that the user can upload a status or emails or upload a post so that we can see all the post over here so we are going to change the design uh of the home page or the for the root view whatever you want to say so for it let's go back to our code and this time we'll go to our let me just close those so this time we'll go to our resource then views and inside views let me just create a folder over here i'll just right click on the view then i'll click new folder and here i'm going to say home let's press enter and inside this home uh we'll create a file so i'll right click on the home folder and then click new file and over here let's say index dot blade dot php let's save it ctrl s and then save so over here we are going to create a basic design so let's just say a normal thing over here let's just say html and then inside the body let's say h on and let's say home page let's save it so this is the index.blade.php which is inside the home folder so how we can get that view over here so in that case if we go to our views okay if you go to a route then web dot php and over here uh you can see that for the root view here you can see route get slash means root view whatever we are seeing over here we are returning a view return view welcome which is this view welcome now uh whatever you are seeing over here everything is coming from this welcome.blade.php every design is over here there you can see we have the dashboard login and the register option and here you can see laravel has under full through feature here you can see documentation uh everything is over here you can see documentation lowercase everything so everything is coming from the welcome.blade.php so what we will do is that we will go to our route then web.php and here in this written view what we will do is that we write over here home dot index why home dot index because our index.blade.php is inside the home folder so folder name is home and the file name is index so home dot index so right now if we save it then if we refresh here it will return us this view home page which is uh this on home page which right over here but obviously this isn't a proper way to return a view so in order to return a view in laravel we need to return the view from a controller so right now we require to create a controller so for creating a controller we need to write a command so we'll write a command over here over here we'll say php rt sun make clone controller and our control name will be home controller let's press enter and here you can see controller created successfully so right now if i go to my app then http then controller here you can see we have homecontroller.php over here so how we are going to call the homecontroller.php from the web.php so for it at the top of our web.php we need to mention our home controller so for it we need to say use capital a double p app backslash here you can see uh http the home controller is inside app http controller then home controller so here we say http backslash controllers they say is backslash home controller home controller okay the o will be smaller so right now we'll have access to the home controller dot php so form here will not write our route like this so let me just comment it out for now so we will write our route like this we say route double clone get to first bracket to single quotation and here we'll say slash then we'll give a comma then to third bracket and inside it we are going to say home controller then we'll give double clone then we'll say class comma will give 2 after class we'll give a comma then we'll give to single quotation and inside the single quotation we need to mention a function name let's say the function name will be index or you can name it anything uh index home anything but we'll go with index then we'll end it with a sim clone so right now we'll go to our home controller and create this index function and from that index function will return the view home dot home dot index so let's go to our home controller and here we are going to say public function index to first bracket then to second bracket and here we say return view to first bracket to single quotation home dot index so what will happen is that from the web dot php uh whenever we'll call the root view then it will call the home controller index function and our home controller index function will written us this view home dot index which is this one home dot index which is home page so let's save everywhere we can just remove this now let's save it here then if we now refresh nothing will change so let's go and make some design for this home page so we'll have a log over here and we also require to have the login and the registration option over here so let's go back and let's first design the never for our website so for it uh inside the body tag we are going to mention a nav deck so inside this snapchat let's say first will have a level i mean this will be the logo for our website so let's so let's over here blog web let's say this will be the name or for our logo and we'll have a few more options okay let me just save it and let me just show you how it looks so it right now looks like this block web and inside this snap we are going to mention email tag and inside this evil tag we are going to mention li li tag and inside the li tag will have a anchor tag so let me just copy this li ctrl c and let's just paste it two times or let's say three times so let's say uh in the first li anchor tag let's say it will be home then here we say about us or let's just over here contact in the third on we'll say register and in the fourth on we'll say login so let's save it and currently if we refresh over here here you can see it looks like this right now we'll change the design so that it looks like a never of a proper website so for it first of all here we have the nav tag so in the head section we can write the style for the nav but instead of writing all the style inside the head let's just do a simple thing that is we'll go to our uh public folder over here you can see we have a public folder and inside this public folder let's create style.css so i'll just right click over here and then click new file and here i'll say style.css then save it ctrl s and then save so here you can see in the public folder we have style.css so right now in the index.blade.php we'll just mention that style.css and we'll write all the style in the style.css so for linking it we just need to server here link and in the hdf we'll say style.css it's better to keep the css file separate because that will be easier to read our code so right now whatever we write in the style.css will have access over here so right now first of all we'll write a style for the nav so let's go to style.css and here and here first of all i'll mention the nav tag over here we'll give two second bracket and let's see here background color it will be sky blue then let's say width it will be a hundred percent so right now if we save it then if we just refresh here uh here you can see this how it looks so let's have this uh on the right side those option home contact register and login so for it here we have the ul tag you can see inside the evil deck we have all the li and the anchor tag so in the style.css we'll mention the ul tag and inside this ul let's say float it will be right so save then let's refresh and there you can see it is on the right side okay let's say for the nav tag let's say height will be 70 px so let's say here height 70 px refresh over here and there you go okay so right now we want all those option in the single line and let's also have some gap over here so let's say in the ul tag let's say here margin uh merging right let's say 20px so it will keep this option a little on the left so refresh and there you go so right now here in the index.blade.php here you can see we also have the li tag inside the eval tag so over here in the style.css will mention ul then li then we'll server here in the second bracket will say display inline block so it will keep every option in a single line so if i now refresh here here you can see this looks different now and there you can see some gap over here at the top and also at the back as well so for it for that case what we'll do is that will give a star sign over here then we'll give two second bracket and we'll see here margin it will be zero and padding it will be zero save then this refresh and there you go so this logo and this option uh we on them in the middle so for it uh let's go back to our code and here uh in the even let's say here line height uh it will be let's say 70 px i think this will make it center okay 70 px now for this on uh what we can do is we'll go to our index.blade.php and here in the level let's mention a class let's say it will be logo save then we'll go to our style.css and here you can see this is a class logo so since this is a class so we need to mention or we need to give a dot over here then we need to server here logo and here we're going to say line height same thing 70px and let's uh make the font with border it will be bold and we can increase the size as well let's say font size we can make it 18 px i think this will be fine okay there you go okay let's also have it a little on the right side so let's say here uh left it will be five percent left five percent and we also need to mention the position to be relative so only then it will move on the right side and there you go and here you can see that uh there is a underline sign over here so let's also remove that underline sign as well so for that case uh we are going to mention here you can see the anchor tag because of anchor tag the underlying uh sign is showing so what we will do is that we will mention over here let's say ul li and the anchor tag and we'll give to second bracket and we'll say here text decoration it will be none and we'll also mention the color for the text as well let's say color for the text will be white do you want to make it bolder okay let's also make it bolder let's say font with bold refresh and there you go i think how it doesn't look good i think black is fine whatever color is this okay let's make it black save then refresh and there you go so let's make a little bit design for the uh register and the login option so for making the design for register and login we are going to use push step class so let me just search over here bootstrap syrian bootstrap cdn link then just go over here you can see go boost up getting started just go anywhere over here then i'll go down and here you can see bootstrap cdn i'll just copy everything from here i'll just copy it ctrl c and then we'll go to our project index.php and here in the head section we'll paste it let's just paste it after this style.css and right now we'll be able to use bootstrap class for register and the login option so for register let's add a class call let's say btn btn uh we'll make it success and for login let's say mention a class it will be btn btn it will be primary let's save it and here you can see b10 btn success and btn bit in primary is a push type class and we are able to use those because we added the booster syrian link in the head section so save it then let's refresh here and here you can see the register and the login option but obviously if we click on the register option it will not work and if we click login option it will not off because uh let's just uh let me just go to the welcome.bed.php and here you can see that from the welcome.blade.php if we click on the register option we are able to go to the register view and if we click on the login we are able to go to the login view because of this hf because when you click on the register button it will automatically call this route call register and this out will return as the view call which you will be able to see in the auth here you can see register.blade.php and we also have the login.blade.php over here as well so let me just go to the welcome.blade.php and form here i'll just copy this htf uh inside the h step we have route register so let me just copy it and if i paste it inside the register href it will be like this then at the same way we'll copy the login route as well let me just copy the login route ctrl c then we'll paste it over here in the login control v control s so right now if we refresh and then if we click register it will take us to the register option and if we click login it will take us to the login option because the login and addition option were created by the jsteam which we write uh where we write all the command uh those are those are created by this command so right now let's go and create a simple design over here where there will be a name and some text and the image in the center of this page so for that case uh here after this nav in the industry dot php we'll just mention a div over here let's say div and inside this tip uh let's just have a level and here let's say a name let's say yami just a simple name then we'll have a paragraph so we'll just make a p tag and let me just copy random text from the internet uh okay let me just copy those texts and i'll paste it over here in the p tag just some random text and we'll have a image as well let's just have the image tag empty for now so right now if we save then if we refresh here in case we have the name over here it text and over here we'll have a image but we didn't give an image over here so before that we want the div to be center we on the name a little bit on the right side so uh inside this tip let's just mention a class and let's say here deep underscore design d gi okay let's just say d d underscore dg and right now we'll go to style.css and here we're going to say div underscore bg and we need to give a dot since this is a class we'll give two second bracket and we'll say here padding uh left it will be let's say 10 percent and padding right it will be 10 percent and then we'll show over here position it will be relative so right now if we save it here you can see padding left and padding right 10 percent so it will will do is that it will uh create some gap on the left side and also on the right side and it will be ten percent so right now if we refresh okay okay div underscore d e g name seems to be correct and in the index.blade.php okay dfdev i made a mistake it will be div so right now let's save it then let's refresh here again and there you can see name and the text is in the center okay it is working perfectly now let's have some gap at the top as well and also at the bottom a little so uh for that case we'll go to style again and we'll say here padding top it will be let's say 10 percent and we can also say padding bottom i think okay basically we added everything for padding let's say 10 percent save then refresh okay i think 10 percent is too much let's make it five percent over here and five percent over here then refresh okay that this is fine now we want to have a image over here so in order to have a image over here we need to keep that image in the uh public folder over here in the public folder so i already have a few images let me just go to my downloads and let me just copy a few image form okay let me just go to my picture and over here we can see some images let me just copy those three images copy and we'll paste it uh in our project public folder so i'll go to my project which is over here basically project then i'll go to my public folder and inside public i'll just directly paste it paste the image here against the image name is 7 14 and 5 and all of them is jpg file so let's just took the 7 so we'll go to our here you can see in the public folder we have the images over here so we'll go to our index.plate and here in the source we'll say let's say 7 dot jpg which is this image and let's also mention the height and width uh let's say height will be 300 px and width it will be 100 percent i guess save it let's refresh and there you can see so right now if we just copy this div and we paste it over here let's say here and here let's see how it looks so we have three images 15 and 14 so let's say here 14 and this one will be 15 so if we save it now let me just show you the images over here it looks like this so if you now save it then if we now refresh here and here you can see it currently looks like this so this is our website so uh we'll be uploading the this text and the image after we log in from our dashboard i mean uh let me just login i think it does yamin at that of gmail.com and password on two three four five six seven eight click login and here this is our logged in dashboard and from here we'll let the user upload some text and images and user will also able to update or delete that data so right now we'll modify this login dashboard so before we start modifying this page let me just show you where is this dashboard view coming from so if you go to our code and then you will go to resource then views and inside views just after this profile you will see dashboard.blade.php and if you go to dashboard.blade.php you'll see something like this except layout except layout now this accept layout and this accept layout is responsible for making this uh top part and here you can see this team laravel system welcome to gestive application documentation lara cast everything is coming from this extent welcome and if we just remove this extra welcome then save it then if you refresh here so there you can see those parts are gone and here you can see dashboard so if here you can see the dashboard that is coming from there so we are going to remove everything from here and we'll only keep this except layout opening and except layout closing and if we now save it then if we refresh here here is the dashboard is also gone so right now what you on is that we have the logout option over here and we have the dashboard and the logo option so what we'll do is that will have a form over here input form and from here we'll be able to upload some data to the database table and we'll also have the we'll also show the uh data over here we'll also have the edit and the delete button as well for the user but before that here you can see there's a background color over here it is kind of a silver color so we'll remove this because right now what will happen is that after or if we write anything inside this uh except layout save it then if we refresh here we have it over here but there is still the background color so we will remove that background color so for that case what we will do is that here you can see except layout and here you can see we have a folder over here called layout and inside this layout folder we have m.blade.php so if you go inside uh here at the line 22 here you can see mean age skin bg grey hundred so we'll just remove this class this class is responsible for making the background color gray so we'll just remove this then save it then if we refresh here here you can see the background color is gone right now so right now we can make the form for uploading the text and image to the database table but before that let me show you one more thing that is currently here you can see currently we are logged in user but if we go to our home page here you can see this is our home page but we still have a login and registration option showing over here which we don't want to happen so what we want to happen is that if the user is logged in uh we will show the username over here and if you click the username it will take us to the user dashboard so currently uh here uh if we go to our index.bread.php here you can see that that we use route login over here and since we are already logged in so it will not take us to the login page if we click login it will directly take us to the user dashboard which is this one and here you can see we have the username over here and what is this username coming from so right now let me show you so if we go to our navigationmenu.blade.php and if we go a little down and here you can see at the line 83 here you can see auth username so from here we are getting this name so right now if we remove this or username from here then save it then if we refresh here here you can see the name is missing currently so from like this we can get the name from the database in laravel by writing auth user so it is getting the name from the user table so right now uh let me just go to the home page and here we'll have option to show the logged in username so for it uh first of all uh let me just show you something in the welcome.blade.php and here uh we have a condition over here if route has logged in it means there is a logged in user then it it will show that this dashboard option else it is in the welcome.bread.php and if there is no auth it means there is no logged in user then it will show this login and register option so let me just copy this part from here ctrl c and we paste it uh in the index.blade.php over before register and login option so here we paste it over here and this if condition will end over here after this login option so we'll see over here at the right of in if so currently uh then we'll copy this auth ctrl c and we'll paste it after this if condition it will write it like this auth and inside this auth will have the username so let me just copy and paste it here logged in username so let me just remove this route and this register text and over here what will do is that in the navigationmenu.blade.php here you can see i showed you how we can get the logged in username which is like this so i'll just copy it over here then i'll paste it over here and then we need to close this auth and we will go to welcome.play.php and here you can see that the off condition ended over here so we will write in dot after this before this logged in i mean before this indeed and here we write the off auth condition if there is any logged in user then we'll show this but when we will show this uh if there is no logged in user so we write over here a condition called else just like in the welcome.blade.php here you can see the condition else and we'll not write this uh same if condition again that is not required for us so as you can see this is really simple let me just extrude again uh if route has logged in then it will check uh the auth user if there is an auth user it will show the auth username or if there is no auth username then it will come to this else condition and show us the login and ensure option and this is the in dot and in this condition so right now if we save it so currently we are we have a logged in user so we shouldn't see the register and login option will only come to this if condition not to the auth condition not to the else condition so save it and let me just refresh here and here you can see only i mean over here but if you click yeah i mean nothing is happening uh so for it what will do is that here you can see that in the welcome.blade.php for dashboard we have a url called uh url dashboard which take us to the dashboard page so let me just copy this url dashboard from here and i'll paste it over here for auth user name so i'll just paste it here and save it over here then let me just refresh and if i click this yeah right now here you can see it take us to the dashboard and currently uh we are logged in that's why it is not showing us the login and register option but if we just log out from here here you can see it is showing us the register and login option so let's login right now again yeah i mean and let me just keep the password on to 34578 then click login so this is the dashboard over here uh if i click this dashboard option uh it will keep us over here so right now uh how to on is that we want some input field and image field so that we can upload some data to a table for uh for those here you can see name text and the image we'll have some uh input field and the image field so that we can upload a image and text and we'll show that over here so for it we need to create a table let's our table name will be post and those will consider those as a post so right now let me just go to the project directory and let me just open a command prompt over here and here we're going to create a table so for creating a table uh we'll write over here php rt sun make clone model and our table name will be post so post and minus m so what will happen is that it will create a model called post and it will also create a migration at the same time so you need to write it like this space variation make model your table name minus m so right now if we press enter here you can see modicated successfully and migration is created successfully so if we go to our code then if we go to our app then inside app we have models and inside models here you can see post.php so it created a model called post then if we go to our database migration and inside migration we have a new table called post over here here you can see create post table so over here uh we will write some column for the table so we say here dollar table this arrow sign then we start here string to first bracket to single quotation and we mention the column name let's say column name will be user name this arrow sign let's we'll also make it nullable let's say and let me just copy it and paste it two times so this one will be for the text so let's say here description then over here it will be the image i think those three is enough so let me just save it so right now if you go to our database here you can see basic project this is our database and here there is no table called post so for it what we will do is that uh let me just right over here control c it will let us type and here we are just going to write a command which is php rt sun migrate so what we'll do is that it will migrate the post table in our database so let me just press enter and here you can see in earning migration created post table so right now if we just refresh here and here you can see we have a table called post over here and inside this table we have user name description and the image so right now let's go and create some input field uh for those username description and emails over here in the dashboard section so let me just go back to my code and we'll go to our dashboard.blade.php let me just remove this and here we are going to mention a form but let's have this form inside the div and inside this div we're going to mention a form and inside this form we'll have some label and input field so let's say first level uh level will be let's say post text or post let's suppose uh let's just say description description and for the description we need the input field so we say here input type text and name equal to description okay let's have this inside a d let's have them inside a div let's cut it over here paste it here and let me just copy it paste it and this time we'll see over here upload a image so for image the input type it will be 5 and the name will be let's say image or file whatever you want so currently if we save it then if we if you share here you can see we have a description box over here and a choose events option over here so let's have them in the middle and we'll also add a simple design so uh here you can see we mentioned a diva but here let's just measure the style over here directly and inside this style let's say padding left it will be 30 then a padding top it will be 10 so he save it let me just refresh here and here you can see it's intermittent not totally so let's add a little more padding left let's make it 45 percent then refresh okay i think 4000 would be better right now let's refresh okay this is better now let's have a text at the top that add a post so after this div let's see over here h4 tag and let's say here add a post let's refresh okay it's smaller okay the text is smaller and also not in the center so let's say here okay instead of h4 let's just say over here normal level and level closing and inside this level let's just mention a style over here let's see here padding left it will be 20 then font size font size will be let's say 20px and font width font wait it will be bold so let's save it then let's refresh okay add a post this is better let's okay let's just have a little gap after this add a post so what we will do is that okay uh before this form we will mention a br tag we see over here br br tag just created some gap so let's say then let's refresh okay there is some gap we can also make some gap you are using via tab uh between description and the image as well so let me just copy this and paste it after this uh description div and uh what we will do is that we will we also required to have a submit button for the form so let's also keep the submit button inside a div and here we'll say input type it will be submit so this is a submit button and let's also add the br over here between this div and currently save it then let's refresh and here you can see the submit button but this doesn't look like a submit button so right now let me just design the submit button so we'll just uh come to this input field and which is our hair style then we'll say here background background color let's say it will be sky blue let's save it then let's refresh and there you go so right now uh if i take my cash flow over here it doesn't show us a hand sign uh so what we'll do is that we'll write some css for that as well so after this dragon color sky blue will say here cash or it will be pointer save it then let's refresh then if i take my cash over here it shows the hand side over here okay let's just make a little bit more design for the button so after this cash or let's say here padding uh let's make it 10 px and border let's say border radius let's make it 10 px as well so right now let's just refresh here and right now it looks like a better button so let's write some code so that we can upload the data to the database table so for it let's go back to our code and here you can see the form over here so inside this form we are going to mention action then method and we also need to mention nc type nc type will be multipart multi part slash form data why nc type multiplatform data because here uh when you are trying to upload any file in laravel you need to mention nc type multipart form data and the matter will be post because we want to upload the data to the database table and here we need to mention action let's skip to second bracket and let's say here url to first bracket to single quotation and we'll see over here upload underscore post so let's save it so we'll go to our route and create this url upload post so after underscore post so we'll go to route then web.php and here let me just copy this route and paste it here so the route will be post let's say our post we'll use the same home controller but here we will write over here we write about here after underscore post so let me just copy it and i'll paste it over here and we also need right now we need to mention the function name in the home controller so let's say here the function name upload the function name will upload so right now we'll go to our home controller and write this function called upload it to close the unnecessary things [Music] so let's go to our uh home controller and get this upload function so here we're going to write over here public function upload to first bracket then to second bracket and inside this upload function we are trying to get the uh description here you can see name equal description and the image so here in the upload function to first bracket we say here request then dollar request so what will happen is that whenever someone click on the submit button okay let me just remove this name whenever someone click on the submit button it will send the description data and the file i mean the image to this url upload post and this url will call the web.php which is this one this route and our this route will call the upload function in the home controller which is this one and using dollar request we'll be able to get the data of the description and the image so here first of all we want to upload the data to the uh post table right in the post table so for it uh we need to mention the post model name at the top of our controller so which over here use app backslash models backslash post we need to write this and you can see app backslash model and then inside model we have post that's why we need to write it like this the p will be capital and here first of all let me just declare a variable let's say dollar post or let's just say dollar data equal to we say here new post you can give that to fastback robert here but it's not necessary so right now what will uh do is that uh in this dollar data variable we are mentioning that our table name so we'll see over here dollar data this arrow sign and here in the table here you can see we have user name field description field and the image so from here we can directly get the description so we'll see over here desk keeps this description crib description okay this description name will directly come from here description i think i did the spelling mistake so it will be like this description equal to we'll mention this dollar request over here we say here dollar request this arrow sign and here if we go to our dashboard.blade.php we mention name equal to description and this name equal to description will go to here so after description we have the image but getting the image is a little bit different in laravel so for now let's just upload the description uh in the database table will upload the username and the image after it after it upload the description so for it what we will do is that with our hair dollar data this arrow sign save so after saving the data we saw over here return redirect uh to first bracket this arrow sign back so let's save it then let's just refresh here and let's just over here test and if you click submit you can see it reloaded and page expired okay here you can see page expire the reason we get this uh error in laravel that is uh we forget to mention at the end of csrf token after the form so we mentioned over here cs rf token so right now it shouldn't give us an error we are getting the error for this csrf token because we did not write it after the form without the csi token the form that doesn't upload it to the database table that is for the secret reason so let's save it and let me just go back and refresh here again let's just see over here test click submit and here you can see it reloaded and it took us back to the same page and if you just refresh over here here you can see we have the description test over here and image and the username is now so first let's go and write some code so that we can upload the username and that thing is uh a user we are not sending the username from the input field we are already logged in as a user and in order to show the username or in order to upload the username to the table that is actually super simple uh for it we need to use auth so first of all uh let me just copy this i will go to our homecontroller.php let me copy it and paste it here we'll say here use illuminate backslash illuminate backslash support backslash packets backslash auth so uh if we write this will be able to get the logged in username using auth so here uh what will do is that here we say dollar data this arrow sign we say here user name equal to and this username will come from the database table from here here you can see username equal to we can just write over here auth auth tower clone user to first bracket this arrow sign name so we will be able to directly get the logged in username if we just write this so what will happen is that it will get the name from the user table directly by checking the who is login right now so it will go to our user table and get the username from the user table which is yeah i mean so currently if we save it and if we now the shifter here and let's say here test two here you can see we did not add the name it tutorial over here but it will automatically take the name from the uh auth so right now if you click submit and if you refresh here here you can see username and the description so right now let's also add the image so for it let's go back to our code so here first of all uh we'll just declare a variable image for the image equal to we'll just get the image first so we'll see over here dollar request request this arrow sign image and here in the dashboard.blade.php we write over here name equal to image and that image name is this one after this we make a image name for the image a unique image name so inside right over here dollar image name equal to we'll write a function called time then we'll give this dot then we'll give two single quotation uh and inside it will give a dot and again at the end of the single question another dot and then we'll write over here dollar image and this dollar image is this one then we'll give this arrow sign and we'll see over here get uh clb capital cli ent client then we'll give the capital o original genome extension extension i think the spelling is correct i hope so sometime people get error for this because they made some spelling mistakes so after this we'll save our image in the public folder so here let me just copy this request image ctrl c ctrl v and we'll give this arrow sign which is over here move to first bracket to single quotation and here we are going to mention a folder name let's our folder name will be uh post will save the image in a folder called post then give a comma over here and after this we are going to mention this dollar image name ctrl c and ctrl v so we do not uh required to create the post folder in the public folder it will automatically create the post folder in the public if you want you can create but that is not necessary so after writing this three line what we will do is that we need to store the image name in our database table so for it uh we'll see over here dollar data this arrow sign image equal to uh we'll mention this image name copy it and paste it here so let me just write comment it out over here let's say image insert part and i'll just comment it out and let's also say here image part here just so that you can understand a little bit clear so we are first of all uh we are getting the image then we are giving the image a unique name then we are storing the image in the public folder and then we are storing the image name image name in the database table image column which is uh this one image column so right now let's save it and let's hope there is no error let's just shift share and let's say here this is a test and let's choose the image right now and let's choose okay let's choose a different image let's choose this image click open and if i click submit here you can see reload it and if i just refresh over here here you can see username this is a text and the image over here image dot stay pg so right now we store the image in the post folder uh which is inside the public folder so here you can see in the public folder it automatically create the post folder and inside post we have the image over here this is the new image that we uploaded now what if the user do not want to upload a image the user only want to upload the description or the post status so in that case we need to change our code a little bit because if we just write anything and if we click submit it will get us a error for the image so for it uh the solution is really simple we'll just here you can see we are storing uh we are requesting the image and showing storing it in the image variable so we'll check if there is any image so we'll just keep a if condition and we'll say over here if dollar image and this if condition will start over here and it will end over here after this dollar image image name so right now we can save it and we can upload data without uploading the image let's just say random things okay we'll not choose any image we'll just click submit directly here you can see it didn't give us any error if we refresh over here here you can see name yeah mean and the image part is now and that is fine so right now uh what we'll do is that will show the uh show all those data description and the image uh to our home page let me just go to the home page over here so we are directly showing those emails statically but those are not coming from the database table so we'll show those from the database table so for it uh what we'll do is that uh here you can see that public function index return view home dot index which is this one here you can see this one we showed the image and the text directly over here all of them so we are coming to this view from this index function home dot index so from here first of all we will get the all the post over here so we'll just just declare a variable let's say dollar post equal to will mention post double clone all to first bracket so uh post post so here auto 11 is that all the post from the post table will be stored in this post variable and so we'll just over here comma compact to first bracket to single quotation will show over here post so we'll send all the post data to this view called home dot index which is this one so over here uh we are showing here you can see name uh that p tag over here some description and the image over here like this so we'll just keep only on div and we'll remove rest of them so let me just remove the other 2df and if i now save it then if i just refresh here here you can see there is only one image and only on text so right now what will do is that so here we have only one diff right now and from the home controller we are sending all the and in the post table we have a lot of data over here as you can see multiple data so uh we need to use forage loop since we have multiple data in the post table so we'll see over here at the right top for each uh to first bracket dollar post as dollar post and this body loop will end at after this closing date so we'll show over here at that of end for each and here uh you can see inside this level we have name so we'll mention it we'll give over here to second bracket and inside it will say here dollar post this arrow sign and in the user table we write over here uh username over here like this so we need to write over here user name so just like that we can get the description and the image so here we'll give two second bracket then okay let me just copy directly from here ctrl c then control v and we saw here description and here you can see image source so here if we save the image uh in the post folder over here you can see this is the image so here in the source we mentioned the first post folder then we'll server here dollar post image we'll get the image name so right now let's save it and if you go to our database here you can see not all all posts have image over here so right now if we now save it here you can see the first post doesn't have an email second post doesn't have an image but that post has the image so let me just show the unnecessary image from here unnecessary data that doesn't have any image let's click choose all and click delete okay right now we only have on data and there you go so this is how it looks so right now let me just log out from here and log out from this user and let me just create another user and i'll post another or i'll upload another post and let me just show you how to how it will look so i'll just click over here and then click log out so right now i'll click register and let's say here john let's add email john at the right of gmail.com that's the password on two three four five six seven eight on two three four five six seven eight and click enter and there you go this is the dashboard for zone as you can see the name over here so in the description i will let me just add a description let's say here i i am john and i am a web developer and let's choose the image from here let's choose this image and here you can see 7.jpg and i click submit and there you go reload it and right now if we go back to our home page and here you can see there is two posts right right now here you can see the name over here and the status or you can say description and the image over here so right now what we on is that let's say the user wants to update their status or update their post or delete their pro clean their post so for that case what we need to do is that we need to have a option in the dashboard so that the user can update or delete their post so for it first of all the user needs to see their post in the dashboard in order to delete a specific post or update a specific post so over here at the top of add a post will add a button over here let's say view post view my post and if the user click on that button it will take the user to another page but the user will be able to update or delete their post so for this let's go and first add a button over here so let's go back to our code and we'll directly go to our dashboard dot play dot and over here you can see if uh padding left 4 dpx so inside this tip will have a pattern so inside this div over here at the top we'll mention a form over here and inside this form will have a input type submit uh you could type submit and it doesn't require any name we will say over here value and we say here view my post so right now if we save it then if we now refresh here okay here you can see a option called view my post this is submit button but this doesn't look like a button as usual so we will modify it so i already designed the uh submit button over here so i'm just going to copy the design for the submit button so here you can see style this is the submit button uh so i will just copy this style control c and i will paste it uh inside this input type submit so paste it over here and let's say the color will be instead of sky blue we'll say here green uh green yellow so let's save it then let's refresh here and here you can see view my post and let's have this input field inside the d so here i'm going to mention it if we will open over here and this tip will in over here and inside this tip i'm going to say style padding left uh it will be less 100 px let's save it then let's refresh and there you go okay let's increase the padding left a little bit more let's say here 140 px and let's also say padding bottom it will be 20 px refresh okay i think this is better so right now inside this form we are going to mention action then we say here method and this two is enough because there is no file uh for this input field so let me just give some space over here so that you can understand that this is a separate form so uh inside this form we also need to mention at the top csrf token as well so the method will be get since uh we'll just send the user from one page to another so let's just over here a action so we'll mention a url over here and inside this url we are going to say let's say view post view underscore post so let's save it so right now uh how to on is that if someone click on this v1 view my post then it will take the user or it will call this url view post so right now we need to go to our web.php and write this url or write a route so let's go to our web.php and here let me just copy this on ctrl c then ctrl v and here instead of post i'm going to say over here get since uh this is a get request and here you can see method is okay and here instead of upload post we are going to see over here view post so let me just copy it and paste it over here and we are going to use the same home controller and here let's just say our function name will be beyond the slope post as well so let's save it and right now we'll go to our home controller and write a function for viewpost so let's go to our home controller and over here i am going to say public function view post first bracket then will give to second bracket and from here we'll just return a view for now return view uh it will be post page post underscore page and we do not have this view post underscore page so we need to create that view so let me just save it for now and we will go to our views and inside these views we are going to create a file called post underscore page so let me just right click over here and then click new file and here i'm going to say post underscore page dot blade dot php so control s then save so here let me just say simple html first and in the body we are going to say my post let's save it and let's refresh now and if i click view my post here you can see our disk space says my post so right now over here in this page first of all we want to have this uh dashboard option over here so for it let's just let me just go back to my code then we'll go to our index.play.php i'm in dashboard.php and here you can see exact layout opening and the except layout closing over here so let me just copy this on accept layout and i'll paste it inside the body tag like this except layout opening and this is the closing so if we save it now then if we now uh go to my view my post here you can see the dashboard option over here at the top so right now over here we will have a table and inside that table we are going to show the specific user post so for it let's go back and here after this except layout we are going to mention a div over here and inside this tip we are going to have a table so let's say here for table we need to mention a table tag and every table has stable row so we'll mention tr here means cable row then inside this table now we'll have that table header first so let me just copy this table header and i'll paste it three times one two and three so first of all let's say here post uh description then in the second table header i'll say image and here i'm going to say let's say update and here delete so after that table header part we need to mention the another tier row for the table data so for it i'll mention another table row and inside this table row we'll mention that table data i mean the td tag so let me just copy this td tag then i'll paste it over here three times and let's just add a dummy data over here for now let's just over here abc let's save it then if we now refresh here here you can see we can see the table over here but this obviously does not look like a table so we are going to write some css for the table so let's go back to our code and here for you can see the table tag tr tag and the td tag so for those three we are going to write some css inside the head tag so here inside the head tag first of all we are going to mention it style over here and inside this style we are going to mention table comma tr comma td and this tab in trtd is this one we are writing the css for this table tr and the td so here we are going to say border it will be on px solid let's say black then we'll say here border polyps it will be follow-ups and let's just mention the color only for table row and the table data tr and td type so here we are going to mention tr comma td then we'll give two second bracket and let's see here background will be skype so if we save it now then if we refresh here here you can see this is how our table look so let's have our table uh in the center over here and let's also increase our table with so for it okay let's just go to my table tag over here and let's say here style and we'll say here with it will be say 80 percent save then let's refresh and there you go so let's have our table a little bit on the right side and also let's also have some gap about here so for it here you can see we have that div tag over here so we'll mention another style over here then we say padding left it will be let's say 15 percent and padding top it will be 30 px save then let's refresh and this is better and let's also have the table data in the center here you can see abc abc is on the left side we want them on the center so what we will do is that over here td inside this tt will say here text align it will be center save refresh okay this is better so right now we need to uh show the post for the specific user john so right now if i go to my table over here you can see john post a upload a post over here only on post so we let the john see his own post over here so for that case we need to go to our home controller and over here you can see from the from this public function view post we are only just returning the view post underscore page so over here we will get the username and using that username we will figure out what post that user made because here you can see that in the table post we have uh two user yamin and the john so using our auth here using this use illuminate support package backslash auth once we add it we can get the logged in user name by writing this line so by writing this line we'll be able to get the logged in username and using that name we will uh figure out that which post john made and will show that specific post over here so using the name we are going to get the specific post and show it for the specific user the better option would be actually uh if we were to use the user id as a foreign id for the post table that will be actually proper but i already did it without the foreign key so i think we are going to follow this way using the name as the unique thing over here since we did not use any foreign key or unique option from here so what you can do is that instead of storing name in the post uh in the post table in in the username you can store the email id from the user table from here so for it all you have to do is that uh here stop name you need to mention the email id over here so i think i'll just keep the name over here so first of all uh in this we underscore post we are going to get the name so for it in order to get the logged in username we need to write this auth user to first bracket this arrow sign name with this we can get the logged in username so i'm just going to copy it and here first of all i'll declare a variable over here let's see here dollar name equal to earth user name so the logged in username will be stored in this name variable i hope i'm clear then we are going to write a fire condition over here so for it again let's declare another variable let's say here post dollar post this is we are going to mention our table name uh which is post to double clone then we'll save our over here where to single quotation and then inside this file pass to single quotation we are going to mention the uh username column from the post table so here we are going to say user name comma to single quotation equal to again comma again to single quotation and here i'm going to say or i'm going to mention this dollar name variable so since this is a dollar name uh so we do not need to mention any single quotation i'll just directly cancel over here dollar name then we'll give this arrow sign and we show our here okay so what it will do is that first of all we are getting the logged in username over here then we are writing a query over here that from the post table we are checking if the logged in username matches with the with this name login name login name is matches with this username if it matches then we'll get the data get that specific column data or specific row data and we'll store it in this dollar post variable so here we'll just keep a comma over here and we'll send that dollar uh dollar post to our this view so it's over here from pack to first bracket to single quotation and i will see over here post and this post is this one okay so i hope i'm clear so let's save it so we are sending the post to the post underscore page view which is this one so here over here you can see that tier so before this tier we are going to mention a for each loop we say over here for each dollar post as dollar post and will in this forest loop after this tier tag will say over here in for it then let me just remove this td and this td table data and this and this as well so inside this td we'll give two second bracket and we'll show one here dollar post this arrow sign user name so let's just show the name first so let's save it then let's refresh here and here you can see that username over here for john so we don't want to see the username we want to see the description so for the install username we are going to say here test encryption save it refresh okay this is fine so right now let's go and show the image so for showing image we first need to mention the image tag inside this td so let's mention the image tag and we stored the image over here in the public folder post folder as you can see so here we are going to say post slash let me just copy this and paste here and our image name over here as you can see is image so here we'll say image let's save it then let's refresh here and we can also see the image but let's change the height and width for the image because it's too big let's say have a fair height it will be uh 400 px and width 400px save then let's refresh and there you go and this is the post made by john as you can see the username over here and if i just log out and log into the gmail.com let's keep the password login and here if i click queue my post here you can see it is showing me the cat image over here so right now over here in the update option will have an update button and in the delete column we'll have a delete button so let's do the delete part first because this is the most easiest to delete a data so for delete here you can see this is this one is for the delete so of inside this td so inside this td we are going to mention an import tag and here we are going to say delete let me just copy this and i'll paste it inside this td as well and this will be for update let's say then let's refresh and here you can see delete and the update button will also modify that design as well so for modifying that design we are going to use the bootstrap so bootstrap serial link so we'll just search for here put step cdn link and i'll go go to this link over here get bootstrap.com and from here i'll just copy this one only if you want you can copy all of them that's fine as well but i'll just copy the first one because this is enough so let me just copy it and i'll paste it inside the head section of our post page so i'll just paste over here so i'm using this bootstrap cd link for making a design for the button so here for the update we are going to mention a bootstrap class so we server here btn btn uh primary now this is a bootstrap class that's why we require to add the bootstrap cd link at the top and here we're going to mention a class it will be ptn btn btm bt in danger so if we save it now then if we now refresh here here you can see it looks like a popper button right now so right now let's do that delete part first so for it uh here you can see href for delete so inside this hf we'll give two second bracket then we'll show it here url to first bracket to single quotation and let's just over here delete delete underscore post then after this single quotation will give a comma about here and then we'll show over here dollar post this arrow sign will get the post id we'll get the specific post id so right now if we save it then if we refresh here and here if i take my cash or over here on the left side you will notice the post tag about here as you can see if i or if i just click on this delete option here you can see in the url we can see three which is the post id over here you can see so so right now we will go to our web.php and write a route for this so let's save it over here then we'll go to our web.php and let me just copy this one then paste it over here and here the route will be get but the url name is delete underscore post so let me just pop it and we'll paste it over here and let's say our function name will be same thing delete underscore post and over here uh since we want to send the id post id uh when we click the delete button so we also required to mention the id over here as well so we'll give a slash over here then we'll be two second bracket and inside it we're going to mention id so right now we'll go to our home controller and create the delete post function so let's go to our home controller and here i'm going to say public function delete post to first bracket then to second bracket and here first of all we will get the id that we are sending from here so we'll just say over here inside this two first bracket will say here dollar id so we'll be able to get the id so here we are just going to say over here let's declare a variable let's say dollar data equal to we mention our table name dollar post to double clone we'll say over here find first bracket and we'll server here dollar id and after this we'll serve here dollar data this arrow sign delete and we'll indeed two files bracket then we'll say over here return redirect rocket this arrow sign back return redirect back means after deleting the data it will keep us on the same page so if we save it now and let's refresh okay let's just do one more thing that is let's just add a random data over here click submit viewpost and i'll just click over here delete here you can see preloaded and the data is deleted over here from here and right now uh there might be someone who may be mistakenly click on this delete button and accidentally delete the data so we should make a alert for this delete button so for it here we'll go to our page underscore uh post underscore page.blade.php and here inside the anchor tag we're going to see over here on click on click return confirm to first bracket then do single quotation and we say are you sure to delete this and you also need to give a semicolon about here so let's save it then let's refresh here and right now if we click delete it will show us a alert that are issued to delete this if i click ok it will delete the data and if i click cancel it on delete data and over here you can see the logged in a login option is gone the reason is because we add the bootstrap cd link uh in the page post for design or button so that is why uh i think it is making some issue with laravel and the boost accidentally we will fix it later so first let me just add another test data over here click submit let's click queue my post and if i click delete click ok it will be deleted and if you want to have the login option over here then what you can do is that you can just remove this bootstrap cd link from here then if we refresh here you will see the option over here but the button design will be gone so for that case what you can do is that uh you can just copy the button design uh form here from the submit option for the update and delete button but i'm just going to keep the bootstrap cd link over here i think that's fine i can still log out from this page so i am okay with that so our delete part is done so right now let's do the update part from here so if i click update and to take us to another page where we will be able to update my status for the image so for it uh let's go back to our code again and let's go down and here this is the update option so in the hdf i'll do second bracket then i'll say here url to first bracket to single quotation and let's see here update underscore post and the same way just like in the delete uh we also required to get the id for the post so let's say here post this arrow sign id let's save it so right now let's go to our web.php and write the route for the update post control c control v and here instead of delete we are going to say update update will use the home controller so that your name is update post the function name is update post and we are also sending the id over here so let's go to our home controller and here i'm going to say public function update underscore post to file bracket would say dollar id then to second bracket and for now we'll just written a simple view we'll just say return view or sorry return view let's say premium will be update underscore post or let's just say update post like this let's save it and right now we do not have this plate in the view so we need to create it so i just click on views then click new file and use over here update post dot play dot php save it control s and then save so let's just see over here simple html and in the body we'll say here update page save it then let's refresh and right now if i click on update here you can see we can see the post id and here you can see update page text over here so over here in this page we will obviously have the header part i mean the username login option and we'll have some input field where it will show us the description and the image and we let the user update the image or the description so for it let's go back first and here first of all let me just go to update page and here i'm going to copy this except layout opening and closing and i'm i'll paste it over here save it then if we refresh here you can see we have the header option so right now uh we'll have a form for input field and the image so here let's just mention a div then inside this tab we say here form then inside this form let's mention another div then here let's say here level it will be post test description and for post description will have a input field input type it will be text and let's say name will be description and after this we will mention another div and inside this tip we have a level okay let me just pop it directly and paste it about here so level will be this change image and the name will be let's say image and the input type it will be 5 because image is a file and we also required to have a submit button so here input type it will be submit and we do not keep our name for submit button we say here value will say update post and we do not recall level as well save it then let's refresh and here you can see post description uh change image and update post option over here i mean the update post button over here so i'm just going to copy the css design uh from our dashboard.blade.php from here so uh from here you can see deep deep style padding left 40 percent and padding top 10 percent so i'll just copy this and i will paste it inside this tip save it then let's refresh and there you go and let's just add some beer tag among them it's a br b attack create gaps actually and beer save it refresh that's fine and let's also copy the design for the submit button so okay where is the submit button okay this is the submit button so if you type submit value okay i'm just going to copy this style for the submit button so copy it and paste it over here save it uh for the submit button your background color green yellow caster pointer padding 10 px and border radius 10 px so this is fine i think update post change name okay so right now over here we need to get the specific post description it means in which post the user click on the update we need to get that specific description over here so for it here you can see the id is three over here in the url you can see and here you can see in the url i mean in the post table for id3 the description is this is a test so for getting this dish description we need to get the specific id so here we already sent the id over here in the update post function over here so here just like in the delete post uh we'll just do the almost the same thing with our dollar data equal to we mention our table name put our clone and then we'll server here fine to first bracket then we server here dollar id so we will be able to get the specific id for the specific post and we'll store that pc post in this dollar data variable and then we'll send this dollar data uh to this view update post so over here we'll just keep a comma over here and we server here compact and here we'll say data only so we'll send the specific data to this update post view so over here i'll just save it then i'll go to our updatepost.blade.php and here you can see this is the level for the uh input field for the description so here we are going to say here value so inside this value will give to second bracket then here we are going to say dollar data then this arrow sign will say this description uh we are seeing dollar data because from the home controller we are sending dollar data that's why so right now if we save it then if we just refresh over here here you can see this is a post which is this one so the same way we can also get the image as well so we will also let the user see the event so for that case uh let's just declare a another okay let's just declare another div over here and here inside this level we are going to say previous image or let's just say current events so previous let's say current image that sound better and instead of this input field we are going to say that mention the image tag and in the source we are going to mention the folder where we are storing the image which is post folder name then we will just say about here dollar data this arrow sign image let's also mention height and width let's say height 400 px and width 400 px save it let's refresh okay we are unable to see the image i think we need to give a slash over here or update save it refresh okay there you can see that image over here current image and we have the change image option over here so let's add a beer over here this will look a little better okay so right now what we want is that if the user change anything over here and then click update post we want the post to be update updated beyond the description of the image to be updated so for it we'll go back to our port and we'll go to this form over here so inside this form we are going to mention action then method and since we are also dealing with file so we also need to mention inc type which will be multipart slash form data then in laravel we also need to mention at the top csrf token as well so the method will be post since we want to update data and in the action we are going to say over here url to file bracket to single quotation and let's say here confirm update confirm underscore update and we also require to send the id for which post we want to update so we also need to send the id so for sending the id we just need to server here dollar data this arrow sign id so we'll also be able to get the id from the post table as well so right now let's go to web.php and create this route so let me just copy this one control c control v and here okay let me just copy this confirm update and paste it here let's also say function name will be same as well and we are also getting the id as well so let's save it so we'll go to our home controller and write a function confirm update so let's go to our home controller and here i'm going to say public function confirm update to first bracket then to second bracket and inside this too fast bracket we are also getting the id as well so first of all just like in the pbs2 function we'll get the id first so let's server here dollar data you can declare any variable okay let's say here dollar post equal to we mention our table name post then we'll server here find dollar id and one more thing and that is here you can see name equal to description then uh here you can see naming all to image so we want to update the data in the database table so we also require to mention over here request dollar request over here then we'll give it comma over here so using this request we'll be able to get the name uh i mean the description and the image in our home controller this function okay so right now we'll mention dollar post which is uh this one then we'll give this arrow sign and let's say here this creation equal to we'll say over here dollar request this arrow sign this creation and here you can see this description will be this first one will be coming from the database table from here and the second this name should be matched with this name in the updatepost.php so after this one we have the image part so let me just copy the code for the image part i already showed you how we can upload the image so the code will be basically the same as well so here first of all we get the image uh here you can see request emails uh okay let me just pop it then i will definite on my own little by little so let me just copy this code ctrl c and i'll paste it over here so first of all over here we declare a variable dollar image and here you can see this is the step variable and here you can see request image now request image will become from here here you can see we also name the input type for file is image as well so it will get the image then we'll check if there is an image so if there is image then we will name that image the unique name using the time function then we'll store the image in the post folder which is inside the public folder here you can see and then over here we are storing the image in the table and here you can see dollar data so here you can see we have post so instead of dollar data over here we need to mention over here post because we mention over here dollar post equal to post fine id that's why and the rest of the things will be same so after this so we are updating the description and we are also updating the image so for image here uh what will happen is that if the user do not update the image then it will keep the old image because here we give a if condition so if the user do not give any image new image then we will not come to this if condition so we will actually keep the old image i hope i'm clear so after this all we have to do is that we need to see over here dollar post this arrow sign save and after saving the data we want we want to stay on the same page so we'll see over here return redirect this arrow sign back and indeed with the semicolon so if we save it then let's refresh over here and let's say update part done over here and let's choose a new image let's choose this one or let's choose this one this time click open and here you can see image is choose and if i click update post i can see it's reloaded and there is a error okay let me check it post method is not supported okay let me go to my web dot php okay here it will be actually post stop gate so let's save it then if i just refresh over here and if i click continue and here you can see the image is updated so right now if you go to my home page then click view my post here you can see update path done and the new is over here and let's go to update and let's say over here update part done on firm but this time we want update the image and if i click update post it will keep the old image here you can see and if i let me just go to my dashboard then click give my post and here you can see update part done confirm but it keep the old image if you want you can only update the image as well let's choose a different image this time okay let's let me just choose a different image from [Music] here click open then click update post and here you can see it is updated let's go to dashboard view my post it is done so right now if i go to my home view and here you can see i mean update part time confirm this one and we also have a image this one as well so yeah this was a basic laravel tutorial i tried my best to make this tutorial as easy as possible for beginner so i hope you learned a lot from this tutorial and if you face any problem or if you have any question please let me know in the comment section and i would actually really appreciate if you subscribe to my channel so thanks again for watching stay tuned and stay healthy
Info
Channel: Web Tech Knowledge
Views: 25,301
Rating: undefined out of 5
Keywords: laravel, learn laravel for beginners, laravel tutorial for beginners, laravel project, laravel for beginners, laravel tutorial, laravel php framework tutorial full course for beginners, laravel tutorial for beginners step by step, laravel php framework tutorial - full course for beginners, laravel project tutorial, laravel rest api for beginners, laravel basic project, laravel full course, Laravel simple project, laravel easy project, laravel small project, laravel tiny project
Id: N04QQAczGyg
Channel Id: undefined
Length: 118min 2sec (7082 seconds)
Published: Thu Sep 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.