Laravel 8 Tutorial - Eloquent CRUD Operation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back to the laravel air tutorial in this video we are going to learn about eloquent thread operation so let's see how can we perform a thread operation using eloquent in level 8 so first of all let's create controller sources to the command prompt and here just type command php artisan make column controller this is controller name let's say controller name is post controller okay now press enter now let's create a model so just type your php artisan make model which is model name let's see model image post also create the migration so just right here okay now press enter all right model and migration both are created so now access to the project and just open the migration so go to the database migration and just click on create post table migration and here just add some column so just write here dollar table arrow string and here the column name just type table string and body okay now save this file and just copy this table name and go to the host model so just go inside the app directory models uh post and here just add the table name so just right here protect protected dollar table is equal to table name okay so just paste here post now save this file now let's migrate the migration so switch to the command prompt and here just type php artisan migrate okay now press enter all right now go to the post controller so just close this and inside the http controllers and from here just open host controller inside the post controller let's create uh methods for create post get post update post and delete post okay so start with create post so just add here a function public function function name let's say function name is add post and inside this that's right just right here return view and let's say view name is post add post okay now let's create the route for this function so go to the web.php file so just go inside the routes then wave.php and here let's create a new route so just right here route it and and here you are i add post okay and here just add the controller name so just write here post controller in column column class then add the function which is at first okay so just copy and paste here also i put here a post controller so just right here use app http controllers and post controller all right all right now save this file and let's create this view so just copy this name and just to go inside the resource directory then views and here let's create a new file at post dot blade dot php okay now just open this file and here first of all add the html5 wallet so just type explanation sign and press tab now change the type all post okay now let's add the boot test tab for cdn so this to the browser and just open get bootstrap.com now click on get started and from here just copy the css pdm and just paste here now copy the js and paste here now inside the body just add here a section give some top padding so just right here style adding top the 60 pixel and inside this section just add here container in row column empty six and also at the offset so this right here call offset md3 okay now add here the card card header okay and here just add the title which is all post uh sorry this is for the add post so just add here add post and also here add post okay now just add here card body and inside this uh just add the form just right here form method post over here that's csrf at the right csrf and inside this form let's create a input field for the title and body okay so just right here form group and add here the label code first just head for the title post title now add here the input field text so just type here input type text name is equal to it and class form control from dash control okay and last folder enter post title all right now just close this now let's create another consistent idea dot on form group this tab now add the label for body and add here this post description all right now create your text area so just write your text area and name is equal to body and class let's say classes on control okay and also set the row so just right here rows let's say three all right now create a submit button here so just right here button type is equal to and inside this just here add post okay now save this file now let's check this so first of all run the application so just write your php our teacher press enter now switch to the browser and just go to the url and that's post okay press enter and you can see the form okay let's add the class to the button okay so here just add class in btn access okay now save this file and just refresh the page all right now let's switch to the host controller and here just create another function just right here public function and function name which is create post okay and inside this just pass here request dollar request now here just add the first model so just right here use app slash models flash post okay now inside this create post form just right here dollar post is equal to new post and dollar post hero type request arrow item okay now for the body just write your post type of body and all that request body okay i'll call the save function so just right here dollar post arrow save all right now return a message so just right here return back with add here the key so just right here first underscore created and just add here the message post has been created successfully all right now let's create the route for this function so go to the web.php and here just write route post which is post controller column colon now save paste here also add the route name you just write here post dot create okay now save this file and let's copy this route and go to the add course address.php and here inside the form just add here action double curly bracket route and just enter the router post dot create all right now let's pre-enter this uh i print this message inside the at post.grad.php file so just head here and read as this key first created so just paste here then just create a larger tube so just right here a lot convert success okay and also save here the role and inside this tip and just hit here the message so just right here says in column column get and inside this gate just pass this key okay post underscore created just close the um just right here and if all right now save this file all done so let's check this so this to the browser and just refresh the page now enter the post title layer so let's say post item is first post title okay and here first post description all right now click on add post you can see here host has been created successfully now let's check so switch to the go to the php my admin and just open database look laravel hit prodb2 okay and inside this database just open post table so just click on browse and you can see here the post now let's create another post so just right here second post title okay and here just type second post description all right now click on add post post added just refresh the table and you can see the second post all right now let's see how can we read the table records so go to the post controller and here let's create another function for getting the record from the table so just write here public function and let's say function name is gate post and just add here dollar posts is equal to post and here just use order by order by clause and just write here id and let's get the descending order okay now just call here get function now return or view and here just write the views name which is posts and compact and inside this compact just pass this post variable okay now let's create the route for this get post function so go to the vapor php and here just write route get and uri let's say uri is post okay and here at the controller name post controller column column class okay get the function name which is getpost okay so just paste here all right now save this file and let's create this view so go to the web reviews dot views directory and here let's create a new file post dot blade dot php okay now go to the addpost.hp file and select all text and just copy and paste inside first.php all right now here change the type here all post and here all post and now just remove all the text from the card body so just remove this and here change the size 12 and remove the offset all right inside the card body let's add the table so just write here table class is equal to table sampled as a script okay and here just add the head inside this this right here here okay then create and here just add the id then post title and here just add the post description all right and here let's just add t body now add here the foreign for each dollar post hedge dollar post now add here the tr td and inside this td just write your double curly bracket dollar post arrow id okay i'll just copy this and just paste two time and here add the title and here just add the body all right now save this file now let's check this so access to the browser and just go to the uri tools okay now press enter and you can see here the outpost okay and here just create just add a link here for add new post so let's add this header just add here a link anchor tag hrdf and just add here and post class okay and just write here our text um add new post okay now save this file and just refresh the page you can see here the link if i click on this thing you can see here the adwords phone all right now let's create another method for fetching the post by their id so go to the post controller and here let's create a function public function function name let's say function name is gatepost by id just pass here the parameter id okay and here the style post is equal to post column column where and here add the column name which is id and compare with this with this id okay so just write here the order id and call the first method all right just return our view all right and inside this right here contact and just pass here this post variable all right now let's create the route so go to the web.php and here just write route it urine posts fast as the parameter id avoid the controller name which is host controller column column class add the method name which is input by id just copy and paste here all right now go to the post dot gray.hp and here just add the details link so just add here action and inside this just add here anchor tag posts posts okay and add the id here so just try to double curly bracket dollar post arrow id all right and here the button class so just write here class btn btn info okay and here just add a text detail all right now let's create this view single post view so just copy and just go to the directory and here let's create a new file and single post dot blade go to the add post blade and just copy all text from here and just paste inside the single post okay now here change the title post details okay and also in the title here post details all right now remove all the text from the card body and here just add the instrument tag and add here the post title so just type here double curly bracket dollar post arrow title and add here the paragraph tag inside this just adhere the post body okay now save this file so let's check this so this to the browser just refresh the page and you can see here the details button okay if i click on this link you can see here the post details page okay um just add here 12 md 12 okay and remove this object just refresh the page and post okay inside the single post all right if i click on this link you can yes you can see here the first post and if i click on link you can see here the second post details okay all right now let's see the next for delete the post so just go inside the post controller and here let's create a function for deleting the post so just write here public function and let's say function name is delete okay and here just pass the parameter id and just write here post where id is equal to this dollar id all right this controller id and here just call the delete function okay and now just return back with just add here the post deleted okay and simple simply add here the message post has been deleted okay now let's create the route for this function so go to the web.php and here just write route get post posts delete post okay so just try to delete as post and add here the parameter id add the controller name post controller column color class and add here the function name which is delete so just copy and paste here all right now just copy this uri and go to the post.php and here let's get another link delete the post so just right here delete post and pass here the post id which is dollar post id okay and here just class just add the class btm btn tensor okay and here just add the text delete all right and inside this host.blade.php file just display this message after deleting so just right here before the table at the rate if session as this game which is post deleted okay then just create a lot of dvr so just right here dot load and inside this tip just print the message here just write here session column column get and just add here this key first underscore delete okay now just close the if directive so just try it if now save this file all done so let's check sources to the browser and just go to the uri post okay you can see here the delete link if i click on this link you can see post has been deleted successfully okay now let's see the update operation so for that just go to the post controller and here let's create another function function okay function name is the edit post and here simply return first of all fetch the record so just write here dollar post post and it's right here find and inside this just pass here the id okay inside this file just write here dollar id now dollar id and here dollar id all right now just return our view and let's say view name is edit post okay and here just write compact and inside this you just pass this post all right now create the route for this edit post function so just copy this function name and go to the php and here just write route okay edit as post add here the id parameter and controller name post controller column column class and then here the function name edit post okay now go to the php file and here let's create a link for the edits just right here anchor tag hrf edit edit post so just right here it let's post and just pass here the post id so right here dollar post arrow id class btn begin success okay and just add here our text edit now save this file now let's create this edit first view so go to the build directory and here let's create a new file edit post dot okay now just to go to the add post and just select all the text and copy and just paste inside inside the edit post also change here edit post and here just remove this route okay and inside this form just create uh [Music] just create here by input type hidden fields let's write your type then okay name is equal to id value is equal to double curly bracket and just right here download post arrow id okay and just close let's see input okay now inside the title just right here value double curly bracket double curly bracket and just right here download post okay now change here the button text submit button takes so just right here update post okay now let's check this so go to the browser and just refresh the page you can see here the edit button if i click on this link you can see here edit first form okay now let's create a function for the update this record so just go to the post controller and here just write a public function hit post okay and just add your request dollar request and here just write down that post is equal to post column colon just right here find and inside this let's pass here dollar request arrow id okay and okay dollar post for the body just write your body color request body now call the save function so just write your post arrow save okay and simply return a message here so you can pack and here just add the message post has been updated successfully all right now let's create the route for this so go to the web.php file and here just add route post and just write here update post okay and add here the controller name post controller column column class then add the function name okay which is update post all right also give the name here post dot update okay now just copy this output and go to the edit codes.get.php file and inside this form just add here route inside the double country bracket route and this right here post dot update okay and printing the message here just copy this key post updated and just paste inside this okay all right now let's check so switch to the browser and just go to the host url and here you can see edit button so just click this and let's make some changes so just write your one one now click on update post post has been updated okay if i click and go the post route you can see here just updated okay let's let's add click in post second post title second post in the steps okay click on add post post added okay if i click on delete link record deleted okay so in this way you can perform the thread operation using electronic in laravel it so that's all about eloquent cloud operations 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: 23,584
Rating: undefined out of 5
Keywords: How, to, Program, laravel (Software), laravel, laravel v8, laravel 8, laravel project, laravel setting up, laravel v8 setting up, laravel v8.0, v8.0, laravel 8.0, laravel 8 playlist, laravel 8 tutorial, laravel 8 lesson, laravel tutorial, laravel 8.0 tutorial for beginners, laravel for beginners, laravel tutorial for beginners, eloquent crud in laravel 8, eloquent crud in laravel8, laravel8 crud, insert, update, delete, edit, crud operation in laravel 8, laravel 8 crud
Id: nSzgMqeQ6Kg
Channel Id: undefined
Length: 41min 0sec (2460 seconds)
Published: Thu Sep 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.