Laravel 7 Tutorial - Update Record Using Ajax

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to the laravel 7 tutorial in this video we are going to learn about update record using hx in previous video we have seen the insert record into database table using hx now let's see how we can update records using ajax in laravel 7 so switch to the project and just open uh student.php file and here just add the header inside the table so just write here ph action okay and now here just add three and inside the cd just add a link so right here anchor tag href is equal to javascript okay and use the button class so just right here plus btn all right and inside this anchor tag just right here okay now save this file and let's check button so go to the students url and here you can see the edit button all right okay now just go inside the controller okay the straight controller so just go inside the app directory then http the student controller and here just create a function public function and let's say function name is get the student by all right and pass here a parameter id okay and just write here student is equal to the student find dollar id and here just to return response your json so just right here arrow here and inside this json just pass this student okay now save this controller and now go back to the student.php file and here just copy this model and just copy and paste here okay this is for add it to the student so just right here now change the id the student edit model okay is the title edit all right now here just add a input middle field so right here input type is equal to hidden okay and name is equal to let the id and id is equal to okay now get the id with the first name so let's write here id defender first name for the last name right here id is equal all right now let's create a javascript function here so here just add a script tag you just write here function and function name gets the function name it says edit script and here just pass the parameter id okay dollar kit and right here the uri for this function so first let's create the route so just go inside the web directory web.php file inside the route and just create just right here route and get and here just write this students and inside bracket id controller name student controller okay function name function name is get the student by id all right and just give the name here all right now just copy this route and go inside the stream.blade.php file and here just paste it now remove this id and just add here plus sign in right your id okay and add here the callback function and this is here straight student and inside this function as id dot and just right here student first name student dot first name okay now just copy this line and paste here three times okay this is last name copy this and paste here and this is what okay now so the edit model so just right here dollar as student this model id this one okay so just copy and paste here dot model and inside this just pass it down okay now save this file and now add this function inside this edit link so just right here on click and just paste the function name edit student and inside this just pass here the student id okay so just write here download that student arrow is okay now save this file and let's check it so switch to the browser and just refresh the page click on edit and you can see here the first name last name email and phone number if i click on click on another edit link you can see here this is called this record okay all right now let's create function uh for the updating the record so just go inside the student.php file and here let's create another function so note function let's create the handle the submit submit event okay for this form so just change the form id here student edit form okay and now copy this id and here just right here dollar has and student edit form okay dot submit and inside this update just write your callback function and pass the e and just write here e dot preview default okay now create a variable where id is equal to you get the id value so right here in dollar um okay now copy this line and paste five times four time okay now here just right here first name then last name email and phone okay now get that okay so right here where is okay and then type type put let's write here then data let's write here the id column id then first name column first name last name last name all right and phone all right and last one is token so write your token and there is two underscore okay okay it requests success then call the function and first here the parameter response response and here just to write dollar as this id this one okay just right here first of all add the id so let's write here id s id and here and just right here inside the double curly bracket download the student arrow id okay now here just try id plus response dot id plus sign then just write here pd and that's child inside the bracket just right here one dot just right here response start first name okay now copy this and paste three time all right now right here two three and this one and this is the last name email this one is email so just write your email and last one phone okay now follow the model so just write your dollar student edit model so just right here yes this okay and model toggle okay and also reset the form so just write a dollar as form id which is student edit form okay okay so just writer has this dot zero index reset okay all right now go to the controller and let's create a function for updating so just right here public function and function name is update and here just past the request request dollar student is equal to the student column column find name so just write your first name is equal to dollar request arrow first name okay now for the last name so just copy this line and paste here free time now last name email and here password phone number so just write your phone now call the save function just right here student arrow save okay and just return a response return response and then jsn so right here and pass there this this object okay now save this file and let's create the route so go inside the web.php file and here just try to route is name which is a student controller and hit function name future name is data student okay so let's paste here add the name route name which is student dot update right now save this file now just go inside the student.blade.vhphp file and here just add the url so right here inside the double quote double quality bracket and just write your route single quote route name with this with student.update so just copy this and paste here all right now type this file so all done so let's check it okay now let's check it so switch to the browser and just refresh the page now click on edit okay now change the name let's add here one one and you never adding one and change the phone number let's say okay now click on submit and you can see here the updated record okay now update this record so just click on edit and add here any text let's say change the email id and now change the phone number let's say one click on submit now record has been updated okay so in this way you can update record using ejects in laravel 7 that's all about update record using the ajax in the level 7 so thanks for watching this video and if you still have any kind of question you can ask me in the comment box don't forget to subscribe my channel thanks for watching
Info
Channel: Surfside Media
Views: 2,795
Rating: undefined out of 5
Keywords: How, to, Program, laravel (Software), laravel, laravel v7, laravel 7, laravel project, laravel setting up, laravel v7 setting up, laravel v7.0, v7.0, laravel 7.0, laravel 7 playlist, laravel 7 tutorial, laravel 7 lesson, laravel 7 introduction, intro to laravel 7, laravel tutorial, laravel 7.0 tutorial for beginners, laravel for beginners, laravel tutorial for beginners, update record using ajax in laravel 7, ajax crud in laravel 7, update record using ajax in laravel, ajax crud
Id: mqgozi5H6xM
Channel Id: undefined
Length: 21min 26sec (1286 seconds)
Published: Sun Aug 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.