Store and Update routes - How to make a Laravel CRUD API Tutorial #4
HTML-код
- Опубликовано: 4 июл 2024
- In this tutorial we will add the store and update methods to our controller.
Get the code here:
github.com/QuentinWatt/how-to...
Follow me on social media:
Twitter: @QuentinWatt
Facebook: @quentinwatt
Instagram: @quentinwatt
Subscribe:
/ quentinwatt
I also make videos here:
/ quentin
Donate with Paypal:
www.paypal.com/cgi-bin/webscr...
I am wondering how I have missed your tutorials on youtube! You are so wonderful teacher. I really liked your videos on react & laravel etc....
Thank you so much.
Thank you so much!
@@QuentinWatt can you make a fresh series on reactjs / vuejs? Or one out of the two which prefer more?
Thank you so much.
Just wanted to say, good job on the videos mate, they're really good. Clear language, good footage and most importantly, good code examples! Keep it going bud.
Did you know sharing this video on your facebook will help my RUclips rankings?
Thank You man finally found some real stuff for API. Really appreciate your work keep it up.
Happy to help
I already made a project in laravel without API, those videos really helpful, I am going to build it with API + ReactJS front, awesome videos newest laravel version
I just have one thing to add though. It might be good practice to put the validation in a new Request file. 'php artisan make:request PersonStoreRequest' This way you can keep the controller really clean and have everything separated.
what a brillent guy in my life.work 100 full effort.Allah bless you.i am promoting your channal .
Thank you. :)
I've been learning php for almost 3 days. I'd learn the basics and after 1 week I can create restful api with it. bunch of tutorials here in youtube include the stuff i dont need like templating and some other stuff i dont care about. I only need an API for my mobile app. thanks to your video mate.
It's a pleasure. :)
Thank you for all tutorial about laravel, i just want to learn about laravel , i usually using native php hahahaha
Laravel will change your life man.
You CAN use FormData and in fact most real-world clients will send it as FormData,. You just have to method spoof it (laravel.com/docs/5.8/routing#form-method-spoofing). In Postman, if you use FormData and add an extra field named _method with a value of PUT, it should work. Laravel will take care of mapping it on the server. This is vital for thing like files which only FormData supports.
For testing the API with postman it's okay to even send a raw query. It's really just there to test how our data is handled.
While FormData is 1 way to accept data. You can also send HTTP requests with Axios which will support put and patch methods. It all depends on the use case.
The other way is to send a POST request with an additional form argument of "_method:PATCH" to tell the laravel that it is actually a PATCH request and it works just fine.
That's for HTML forms where Patch is not a supported method, but this works just fine using axios.patch() or some javascript method like that.
Instead of 'form data' you just need to use 'form url encoded' so you don't need to use raw query
You're correct.
Should store() in the controller have a return type of PersonResource also?
It does in my final project
github.com/QuentinWatt/how-to-make-an-api-with-laravel/blob/master/app/Http/Controllers/Api/v1/PersonController.php
tutorial 4 -> how does it knows which ID it needs to update? you pass it in the URL but i see no reference to it in the code.
it is a built in feature? (like it shows on the route:list?)
It accepted the ID and used the Person model to find the correct person.
That was what this part is for.
`Person $person`
Hello, first of all i wanna say your tutorials are amazing, and I have question about restControllers, for example in update or show method if person doesn’t exist! How we can show errors , i always use try catch but i want to know about rest controllers
Following this course, Laravel will automatically throw an exceptions with a message for examples you have mentioned.
Hey, Thanks for the Tutorials, I liked it very much. I tried to built small api using this notes. And also can you please provide the way to install CORS Middleware on this API?
Laravel 7 actually has a CORS package shipped as default, but you can install it from here:
github.com/fruitcake/laravel-cors
You simply set the allowed origins as an array in the config file. Instructions are in the Readme file of the repo.
@@QuentinWatt Thank you. You are a pro...
Could you please recommend me the advanced API course.Thank You in advance.
I'm not sure who to recommend but there are plenty of courses like this on udemy.
How can pass csrf token to postman ???
You can set those in the headers tab. Add a token and then get the token from your browser.
Although csrf token is for a web route.
Typically an API would use a different guard and require a bearer token.
update data nahi hu raya ?
"message": "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST.",
Make sure you are sending the request to /person/, maybe you are sending a put request to /person
As NickyP pointed out. You may be using the wrong route. I show you how to check routes at 1:11
sir update nahi hu raya