How to Edit , Update Data In Laravel Step By Step | Laravel 8.0 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to webtech knowledge this is yamin and today i'll show you how we can edit or update data in laravel okay so as you can see we have name email and photo over here so i'll show you how we can update this uh name email and photo so for this the first thing we are going to do is that we are going to have a edit button over here okay so let's go to our code so this is our code uh where i am showing all those data from here you can see uh inside of uh for each loop you can see id name email and file uh which is actually our image and over here you can see a delete button okay this is where i am showing all those data okay so the first thing we are going to do is we are going to add a edit button so for this i am just going to copy it ctrl c and ctrl v now we are going to say over here edit okay and let's over here btn success okay now let's just uh remove this part for now okay ctrl s now let's see how it looks let's refresh okay we now have a edit button over here so when someone click edit button then it will take us to another page where it will show all those data name email and photo and from there we can edit our data okay so let's go to our code now over here we need to create a route ctrl c ctrl v now over here we'll say uh edit page edit page okay and it will uh take the id from here and it will uh show the data uh from that specific id to this edit page okay so we don't have this route we need to create this route so we need to go inside route and then web dot php so i'm just going to copy this one and paste it over here so route get and our url name was edit page right so i'll just copy it and paste it over here and we need to give it a function name so i'll say over here function name will be edit page as well okay and we also need to mention over here id okay so uh when someone click this edit button it will send id to our route okay and our route will send this id to the controller uh which name is update data controller okay so we need to go inside this controller and create this function so let's go to controller which is inside app http controller over here you can see update data controller so let's click it and let's uh create our function so let's say public function edit page okay sorry edit page and inside it we need to write id so it will cache our id okay then we need to declare a variable so we will say dollar data is equal to uh we need to write our table name over here which is personal which is our table name okay i'll show you my table over here right now now this is my table name here you can see name email and file file is actually image okay uh and this is where i am showing all those data actually okay so let's go back to our code and one more thing we need to add model our table model over here like this use app slash model slash personal okay you need to add the model uh inside this like header part kind of thing okay so over here you need to write find dollar id okay now you just need to return the view return view now let's say it will uh return view to edit page now we don't have edit page we need to create this page with the data of of this data okay so what will happen is that uh when someone click this edit page it will send this id to our route and our route will send this id to our controller and our controller will uh send the data of the of that certain id to our edit page okay so let's save it and so now we need to create edit page okay so we'll go inside views and over here i'll just right click and click new file and over here we'll create edit page dot blade dot php so control s and then save okay so over here i will say html over here let's say edit page or update this now we want to show all our data uh let's say in the center so i'll just say center and then let's say h on again again edit page edit page okay now let's try to uh show a data so in order to show data we need two second bracket and then dollar data which is uh this one dollar data we are sending uh all those data to our edit page so dollar data and you can see uh in in my database that we have a column called name right so dollar data name so let's save it and let's check if it works or not let's refresh and click edit okay we can get the name over here okay so let's just uh give it a good look so let's see over here uh level level name now over here we will have a input field type will be text and name equal name and the value will be this one dollar data name okay so let's save it and i'm going to copy it and paste it over here and instead of name this time we'll use email which is this one email email and the type will be email name equal email and data equal email okay so let's save it and i'm going to add a br over here just to create some gap so let's save it and let's refresh okay you can see over here that we have name and email feed uh and we are getting data from the database now let's add our image over here so for adding image uh let's just copy the image part from here i'll just copy it and paste it over here ctrl v okay here you can see that our image is inside a short inside public folder shortest dollar data file i will show you inside public here you can see a shortage folder inside this we are actually saving all our images okay so uh let's also add pr over here as well okay let's save it and let's refresh again now we are getting the image so now let's uh add a level let's over here chance image and then uh we will add a input field input type will be file and the name will be file as well let's save it and then uh let's add here i'm just going to copy it now let's add a submit button over here input type will be submit and let's say the value will be update okay so let's save it and let's refresh okay right now we have a chance image option over here for if we click it we can change image and then update option if you click ok so right now we need to add form in this page so i'll add form over here i'm just going to cut it and paste it over here after submit ctrl s and then uh inside this form i will say action and then method after this uh it will be enc type since we are adding file and okay that's some nc type will be multipart form data okay and the method will be post since we will be sending data to the database and we need to add a route over here so we will say url and then inside it will say update and we also need to send a id so for this we need to write dollar data id okay and one more thing we need to add a token so for this we need to write at the right of csrf okay control s and we need to create this uh route over here inside web.php so again i'm just going to copy it and paste it over here and this time it will be post instead of get okay so let's write post over here and our url name is update okay so let's we'll just write over here update and we will use the same controller and let's change the function name to update okay so let's save it so let me explain it again so when someone click the uh submit button i mean the update okay it will uh send the id to our route and our route will send this id to our controller okay so we need to create this function right now so let's go to our controller and then let's see over here public then function update and inside this update we need to say request dollar request then dollar id it means it will catch the id and over here we need to again do the same thing that way we did over here just say dollar data equal personal then find dollar id okay and right now i'm just going to copy a little code from here ctrl c ctrl v now this part is for our images actually so what will happen that it will request the image file okay then uh then it will save it inside shortest okay then uh the data will be same in our database okay and right now we will say dollar data name is equal to i think it's a dollar request dollar request name and again i'll just copy it and paste it over here for email okay email and email so it will uh save our name update our name and update our email after this just dollar now we just return and i just copy this part from here i sometimes do mistake and paste over here okay so uh let me explain it again so that you can understand it very easily uh when someone click the update button it will send the id to our route which is this one and our route will send this id to our controller and our controller will uh get the id and find the specific data and uh change the image name and email and then save it into our database okay so that's all so let's uh go to our code let me just save it again just to be sure okay let's refresh let's go back first okay now let's click edit let's change the data here we'll say uh captain america let's uh change the email to captain and let's keep the image the way it is let's just click update okay now let's go back here you can see our name and email change okay this time we will also uh change the image as well okay so i will say just captain over here and over here i will again add america and i will change the image this time okay let's choose the image from here let's see we have another captain america okay uh let's just choose uh hulk this time okay so let's open and click update okay our image is changed and sourced all the data so again just uh go back and check if it changes over there okay it also changed over here okay so that's how you can uh update or edit data in laravel i tried to explain it as much as possible but if you have any problem then let me know in the comment section i will surely surely reply back and if you face any problem i will give you a solution and if you want to support me then please like this video and subscribe this channel thank you very much for watching this video
Info
Channel: Web Tech Knowledge
Views: 931
Rating: undefined out of 5
Keywords: update data in laravel 8, how to edit and update data in laravel 8, how to update data in laravel, laravel crud, how to update data into database in laravel, how to edit data in laravel, laravel update, how to edit and update data into laravel, laravel update database record, how to update value in laravel, laravel update data in database, how to update database table in laravel, update function in laravel, laravel edit, laravel update record by id, update single record laravel
Id: UmOqUH-7q_I
Channel Id: undefined
Length: 19min 31sec (1171 seconds)
Published: Tue Mar 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.