ADD, EDIT, DELETE, LIST using Laravel | Laravel CRUD Operation | Laravel 8 | Learning Points

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi friends welcome to laravel a tutorial in this video we will going to create a laravel crude application that means we will learn about basic add edit delete and listing operation using laravel 8. so here is my database name is laravel 8 i need to set in dot env file so i already set up database and here you can see this is my laravel 8 database now i want to create a table that is postable and i will add some data into this table and i will update data from this table and will fetch records from this table that means add edit and listing operation and the last will do a delete operation using the level 8 so let's create a model and migration so to create a model we need to use php partition make model and here i am providing my model name is post and i am creating migration that is minus m so model created successfully and created migration is the create post table so just go to your project directory and repress this so you will get in the database folder in migration section will get the create postable migration and a new model that is post model is created so first modify the migration so i want to add some column into post table so i will add suppose post name and this is the string type and i want to add another that is text type and the column name will be suppose description the migration is set and now i am going to provide the table name in the post table so just use protected dollar table and the table name will be the post table so just use this here so now save the model and to run the migration so to run the migration we need to use php partition my gate so my migration completed and if you refresh our database we can see the new table created where the name and description column added so name is the behave 255 and description text which i added description was the text so now add some data in the post table using the from so let's create a prompt in level and add some data using this form so first create one controller so to create controller go to use php artisan make controller and here my controller name is suppose post controller okay just enter this so just refresh and if we check in http control section so we will get a new controller that is post controller so let's create a method and using this method we will open a add from so first use suppose public function and suppose my function name is at post and i need to add a view so here i will add suppose written view suppose my view name is at post so we need to create a ad post blade in our resource views folders so here is my resource folder and inside the view we will create a file that is at post dot blade dot php okay so let's add a from here so i am using the html5 element the title will be the add post so inside the body we will add some basic from okay so we need to add the tag that is form tag and in the form we have some method that is method and there will have some action so when we submit the from what will be so let's add some field that is input type text and the name so i'm providing the name and the value is now for blank and let's add beer so i am providing the label so here i am adding the label that is suppose the post okay and i want to add another that is description so just use description after that beer okay and it will be the text area so use the text area here and close the text area and provide the name of the text area that is here my texture name is suppose i am writing description okay and let's add some methods suppose i want to add the from using post method so i am preparing here the post and we need to create a submit button so input type submit and i am providing the value that is also submit okay so when we click on submit button a action will be called so here i am using the action that is route save post okay so now add this route in our web route and call this function in the web route so we need to add two hours in our web.php so here the web.php so first we need to add this post controller here and after that we will add suppose i will create a first route that is get and here i will add the add post and after that the controller name double colon and here we're going to use the class and after that my method name is at post so just right here at post and suppose here i am to write the name of the route that is post. okay and i will create another route that is when we submit within the post method this save dot post will call so here my route name is safe.post and i will use the post method here and when it will call suppose i am creating a function that is say post so just declare this function and the post controller okay so public function say post okay so now call this at first to view the add post blade so to call this we need to use the add post here so first run the server to run the server we need to use php attrition serp so if we click on add post here we will see the post and description here okay so i am using the beer here so it will looks better okay so now we need to submit from to save the file one thing in larabel we need to use the csrf token okay so just csrf here so if you add cs array then automatically it will generate a hidden field where the token will be generate okay so just replace this page so now if we submit the request will call so here my say post will have the request so request suppose i am taking this request into the request variable so now we need to save the post and description value into the post table so we need to use the db and name of the table so that is the post table and after that i will use insert method to insert so now i need to take the array so we will insert the name and description here so just write down name and name equal to request dot name and another that is description so description here to request description so here the name and this name and this description should be match with the post table and this name and this description will match with the viewplate okay so if we run this it will insert this record into the post table so here i am using the db so when we use db here and so after the submission it will return to the same page so there is the add from page and and i am setting some session so i will show the post edit successfully and here i need to mention the session that is posted so here it is the session value so using this poster session we can print the success message in the add post okay so just print the success message here so i will print the session value here so if session has the session value that is posted then it will print the session variable so just ending the if and after that i am printing suppose in span i will print the session value so to print session value we need to use the session and after that the gate so using the gate we will get the session value the posted okay so all are set that is controller is set and the web.php that is route is set so both are same at post and at first we can use the different also there is a different method so we can write this so just run this so first run the add post from here oops sorry the session name will be the caps okay so the session so just add some post so my first post and my first description so just submit this so here you can see the post edit successfully so if you rephrase the post table we can get my first post and my first description so add another post my second post and my second description and refresh the page again so here you can see the my second post also so now i want to make a list to show all the post data in a single table so just add another function that is public function post list okay so here we will get all record from post table so i am using the post variable here and after that the db and i will provide the table name that is post and after that we'll fetch all record so use the gate method we can get all record and return the post of hello into a view so my view name will be return view post list okay and pass the post value using the compact method so just use compact and pass this so okay now we need to create another blade that is post dot list so here we will create another blade in view that is post dot list dot blade dot php okay so now create the html5 element so here we will write in title that is post list and i will create a basic table that is table and after that i am closing the table so in tier tag i will use the th for heading and closing the th here i will print the id and in the same way i will print the name and description so here i'm providing the column name name and the description and i'm closing the tier tag and i need to display the post value here so here i will add the for each loop so for each dollar post whatever we have hello that is dollar post as dollar post so now ending the forage and inside the forage we will use the tier tag and inside the tier tag in td we will show all the record so here i will create the td so here first i will print dollar post id in the same way we will use the name and description so here we will see the description and so i am literally designing the table that is inside the head i am using this suppose basic style that is style okay so here i am adding some table style that is stable suppose border collapse i'm using the collapse and with hundred percent okay and i am adding style for td and th so we can add at the single time so i am just using the padding 5px and i'm adding the border suppose 1px solid okay whatever now we need to add the post list method into our web.php so here we will add the postlist method so i am using the get method and i need to call this postlit function here so here my function and post list and my url will be the post list and i am providing the name that is post list so now run this so if we run this we can see the id name and description that is my first post my first description my second post my second description so now at the add post button here so in the listing page i will add the add post button so just before the table i am adding a anchor tag suppose an anchor tab age rep and i have to use the routes here for add method so label add post okay and close the anchor tag and now my route will be the route that is the name of the route is post dot at so just add this post dot ad here and i'm using some basic inline style so here we will get the add post so if you click on add post we'll get that from so now we need to edit and delete the value so to add and delete we will add the action column and we'll have the two links for edit and delete so in the listing page we will add the another column that is th and here i will write the action column and i will add two links that is in td so here i will add the anchor tag and closing the anchor tag this is for edit and i will add another for delete okay and add the hyperlink here so use href okay so use slash edit post and we need to pass the post id here so just pass the post id and in the same way we need to delete the post so to pause delete we need to use the delete post and we need to pass the post id to delete okay so if you refresh this page we will get the tooling that is edit and delete so now we're going to add this link into our routes so just add this so here we will copy and paste here and i'm pasting the another so first for edit post i am writing the edit post here and i am providing the name that is post dot edit and my method name edit post okay and for delete we have delete post so just write here delete and the name post or delete and add the method name that is delete post okay so let's create this two function into the controller so in the controller we will create the two function that is public function edit post and another function that is public function delete post okay so now here we can see in in the listing page we are passing the id so we need to receive this id from this method and we need to pass the same from the routes also so using this id we will edit or using this id we will delete okay so my routes and control is reduced so first we will use the post variable and we will find from db where we need to edit so first we will use the table and my table name is post and will and we will use the where clause here so i will fetch the id from the providing id and after that we will use the first so it will do so it will fetch the first record so now we will create another view that is written view edit post and we will pass the post value into this so using the compact we will pass post okay and now create a new blade that is edit post that is edit post dot blade dot php okay so copy this from the add post section so here will be the same but when we edit the value should so so here i am passing the value so just use this value so here we will write in a value so dollar post arrow name and in the text area we will add dollar post and the description so here my description okay so now if you click on the edit post our edit file will open so here we can see the my first post and my first exception and my second post and my second description so now we need to save this so just change the route that is update post and this is the same and here i am taking another field that is input type hidden and i put the name that is id and i am passing the value for id here so here just write dollar post id okay so using this id will update in the post table so just create another function that is public function update post and we need to receive the request so here i am using the request in the same like add and we need to call this function from routes so we'll call so my function name is object post and here i will add the update post my route name is update dot post okay and write the update comment in the update post so use the db and the table name so here my table name is posts and i want to update so we will write the update here and add the array that is same like save and we need to update in the particular position so we need to use the where clause here so we'll update where the id is that is requested already and after the update we will return a statement that is written back this with that is post update and i'm providing here the value post updated successfully okay and use the post update session here so here just replace this post update session so all are set so now run the edit page and here i am updating i am using the updated and just submit here so here we can see the post updated successfully and we can see that my first post updated and if you replace in database so here we can see the name also updated and now i want to delete records from post table so to delete record we will use so here i have a list there is delete post function and in web dot php we have the delete post so we will create the delete first function and the post controller so very simple just like update we will write the delete here so we will use the db table and i will provide the table name that is post and here i will delete where id equal to given id so here id equal to the given id that is already and after that just use the delete function and after that we will return a message so i will add a session that is post delete and here i will write the post deleted successfully so just use the session in the listing page so just use this so copy from another section that is session and paste it here after the body and use the session variable that is post delete okay so if we want to delete the my second post if we click on the delete it will be delete so i have deleted supposed it is successfully and if we check database we will see the post detail successfully so if we want to add another so i am adding new one and adding new description [Music] we can after that if we check in database we can see we can see in the database table also we can edit this so new updated okay so just submit and just refresh the page so i am adding a new and updated and after that if you refresh here so it will update it so we can understand the basic crude operation using the level 8 please comment this video if you have any queries please like and subscribe this channel and next day we will discuss about laravel from validation
Info
Channel: Learning Points
Views: 30,020
Rating: undefined out of 5
Keywords: Laravel, Laravel 8, Laravel Tutorial, laravel crud application, laravel 8 crud operation, laravel 8 crud tutorial, laravel simple crud application, laravel crud, laravel 8 crud, basic of laravel, add, edit, delete, add edit delete in laravel, laravel tutorial, learning points, latest laravel, new technology, working with laravel 8, basic laravel crud, laravel tutorial for begineer, what is laravel, laravel form handling
Id: D7Vyr5rPUIE
Channel Id: undefined
Length: 31min 16sec (1876 seconds)
Published: Mon Oct 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.