Laravel 7 REST API example . GET & POST method

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everybody welcome to my core brand Channel today I'm going to create a three basic facilities in laravel 7 we sing get and post method you're going to create three basic EPA's own is to create book information with book name or the description and the second one is to list all the books and their own is to fit specific book information using the book ID so this is these are the end points so this second URL to fetch all the book information from database the last one is to fetch a specific book information using book ID so the first step we have to do is to create a table Carl books so I need to create a migration file so please be honest and make my grid sorry make migration great books table it's actually created as a magician fire under migration directory here so this for migration fire here we need to specify the column names of the table so name order and description of the column names we need to create so book name which is his worker so I am sitting is a stream second only is the order name so I'm sitting as author the last one is the description so I'm setting a cert text actually need you know need to set us a text so book me or the description of certain migration file so when we brendham so right now we have no tables called books in our table so we need to create the books table using the migration so I am going to run the migration this is a campaign for running the migration history understand my grade this will create a new table called books so Ashley is created we need to check the database that it is created Oh No okay so remember a flashing the page and checking that books table is created yeah with a book name or the in description so meditation is already done so now we need to create a model because we are using eloquent ORM so we need to create a corresponding model class for the table books so I'm creating a new model called book PHP Anderson make model book so it's simply created a new model and our app directory that place P so we need to specify of the table name which we are referring so books mr. taebel it's go put it but that table is equal to books so created a model class book and he said the table name no we need to create a controller corresponding controller so we am creating a control called book controller so it's created a new control under HTTP directory here our controller books controller sorry book controller in a PHP we need to specify you need to write the rules for the API so I am writing books controller actually I'm creating a new AP for posting the form data and this is our URL with form data book named author and description this is a reindeer endpoint okay who say book is a function we are calling so we need to create the function say book we need to pass the request class here we need to sit because we need to give the form data from the positive method make sure you are imported the corresponding model class in your controller so I'm importing the book model so I'm creating an object for a book class we will get all the post data in requests variable so we need to set that request book name and book other is equal to dollar request book sorry order copying this water copying pasting and studying as a description and worklist parameter so it's a our description okay you see this book named FC refers to the table name so a table column name and other actually refers to the table column name order and the description also refers to the corresponding column name description now we need to save the data in the table so we need to call the same material yeah we're done so good I'm sorry you know see actually able to see the data in the table so make sure you order the response class we use the response class of to return back the response in Jason I'm using this class you can use response address if you want to returning back response yes new created object book with the status quo - not one this is our data which we returned back with newly created data we can check using postman so how are you early CP / book with post by post method data yet you've seen post method I know for later good name and [Music] just using some name reporter actually have some daytime me so I am just copying pasting all the data oh yeah you meup drones and the other actually I'm sitting us over the list using test so description yourself and see no so ladies so it might at least not actually om we are not used to first meter still there comes so there is something [Music] dollar-something issue oh I didn't save the API rod bhp I think so this way there are comes so we are using the post materia end of the you our list is yeah we actually created a new entry with ID 1 and book name Game of Thrones and other tests we sexually created a new data table so these were in URL I mean in point and it's actually calling the blog as a book functioning broken dollar sorry Buchan dollar actually this is her say about function which is all the job it's actually creating a new entry with two not one status okay no going to the second APA it's a list of all the books which we serve in the table right now we have only one record in our DB okay so we are going to create a P period PHP okay we are using the get method so not post method copying this on seeing the get method books and the function is list a book mr. books so we're eating in your function currently lists books in book controller actually we are facing all the data from the table actually all the books information from the table so we need to call the function all which is an eloquent function so G so how we fish all the data from the database using the eloquent using the all function so that's it actually you need to copy this and need to copy this one and piece here change this status you said 200 I think [Music] so let's check this adjusting these festivities you are you have to sing get method AP / books scene it later so mostly there is some actually there is some issue I need to check think there is there must be some machine or function such as assigning the data into under variable but this is not the issue let me check I'm just sending the data in another variable let's check it still showing there so I think the you are actually there is issue in the URL there is a typo in the world they used to wrong URL I used the euro room you are their spy the error shows so these are right URL you think so yeah that's it so we have the correct URL and we fetch the data I'm deleting although breakfast and this you are actually right now all there is only one recording the TV so it is listing here with d-19 book name we have team of Thrones now we are going to the last AP which actually will return the specific book information you see the ID so going to a period PHP again copying the view what I'm changing something book /ib Italy is passing an ID to get out the book data what specific data using the ID so the function is I am writing as I get booked this our function get booked no binding that function into our controller controller so public function book with an ID yeah a parameter Sadie I'm using a fine method for getting corresponding data using the ID to getting I mean to get the corresponding data from table using the ID we can use a fine method find then passing that ID so we are using fine method to get the data and turning back that book information so you're less AP / book missing the good meter box / / ID so again Samara no just check it so very still so I I didn't saved a pier or PHP and okay no no it will not work yeah it's working is really getting that cosmic data using that ID which terms single entry so so I'm creating a new data say new book information using some data from here I go into our some more data in our table so I'm using the post method I am creating a new method I mean a new data so I'm changing it to the new book name and the hotel's name is this so yeah I created a new entry with ID 2 now I'm missing all the red using it method so slash box so we get all the data with ID 1 & 2 we get our data from the table above information learn more data I think industry - real actually I am not using any ap validation and any FPS indication so you must be our proper validation and authentication or the AP right now they peas are open so I am creating a new entry and see the fantasy no fantasy no well you sir so actually oh okay nice note they took the ID yeah it's created a new entry the way of kings no Lister books yeah just our data I hope you so that's it ah here and I hope you you enjoy the video so please subscribe the channel for more videos probably in the next video I am going to tutorial for human framework thanks for watching don't forget to subscribe
Info
Channel: Coders Branch
Views: 869
Rating: undefined out of 5
Keywords:
Id: I67hQ3GkOtM
Channel Id: undefined
Length: 24min 53sec (1493 seconds)
Published: Mon Jun 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.