Laravel 8 tutorial - Put method API

  Рет қаралды 39,925

Code Step By Step

Code Step By Step

Күн бұрын

Пікірлер: 43
@williamburt5586
@williamburt5586 3 жыл бұрын
Yes you can also use POST for updating and it will work. However post is normally used for inserting data and when updating we usually use PUT. This makes it easier and quicker to review the code and know what it does.
@saikumarkandikonda431
@saikumarkandikonda431 3 жыл бұрын
Post is used when inserting new values into database and Put is used when we are updating the existing values.
@PapaPlayerOp005
@PapaPlayerOp005 2 жыл бұрын
Put method is not supported error
@dineshravajani2698
@dineshravajani2698 3 жыл бұрын
Well, POST method is basically used when creating new resource/record in database table and PUT method is usually used to update existing record in database table. However if we use POST method to update record then also it will work very well but it is recommended to use PUT method when update any existing record.
@HemantKumar-dreamer
@HemantKumar-dreamer Жыл бұрын
Can you please create a detail video on POST vs PUT vs PATCH and cover idempotent as well. Thanks for this video.
@moronibr
@moronibr Жыл бұрын
Your serie is awesome
@sagarpandey4873
@sagarpandey4873 3 жыл бұрын
YES we can use post method also because same thing done in post api in put api we can find table by id and save data in same as post api and we can not pass any other variable in put method
@tellavenky5079
@tellavenky5079 3 жыл бұрын
Very thanks sir i have learn for the so many things in this tutorial
@zoroXgamings
@zoroXgamings 3 жыл бұрын
yes you can do it, just send the id of the device in hidden field and fetch the device from database using that id in controller and then assign the new values and at last use save to make the changes
@julianbedoya2058
@julianbedoya2058 3 жыл бұрын
I was looking for another thing but this was very helpful xD
@davidfelipehuertas2458
@davidfelipehuertas2458 4 жыл бұрын
Thanks from Colombia
@ErGhanshyam
@ErGhanshyam Жыл бұрын
* POST Method: Purpose: The POST method is primarily used to create a new resource on the server. When you send a POST request to a specific URL, you are telling the server to create a new resource using the provided data. Use cases: Use POST for actions that result in the creation of new resources, like creating a new user, adding a new item to a shopping cart, or submitting a new blog post. Example: When you create a new record in the database by submitting a form or sending data to an API endpoint, you typically use the POST method. * PUT Method: Purpose: The PUT method is used to update an existing resource on the server. When you send a PUT request to a specific URL, you are telling the server to update the resource with the provided data or, in other words, replace the entire resource with the new representation. Use cases: Use PUT for actions that modify an existing resource, like updating a user's profile information, editing an existing blog post, or changing an item's details. Note: It is important to emphasize that according to the RESTful convention, the PUT method should be idempotent, meaning multiple identical PUT requests should have the same effect as a single request.
@32anchalprajapati21
@32anchalprajapati21 Жыл бұрын
Are u a developer. ..
@ErGhanshyam
@ErGhanshyam Жыл бұрын
yes i'm a laravel developer.
@NurulIslam-dw8yp
@NurulIslam-dw8yp 3 жыл бұрын
Yes, of course put, patch , delete these things are just fancy names to let the url have meaningful names
@qLac3
@qLac3 4 жыл бұрын
thanks for the videos!
@Abhi_JW999
@Abhi_JW999 3 жыл бұрын
can we use one model for different controllers will it work?
@codestepbystep
@codestepbystep 3 жыл бұрын
Yes
@patricktisserant
@patricktisserant Жыл бұрын
As far as I know, for INSERT and UPDATE, you must use PUT method. Difference between method is not technical. POST method is used for API you can call mnay times with the same result. Instead of PUT you cannot. In your 2 examples, you must not send 2 times same data because create duplicate row in the table, so it is PUT method allowed. POST method is more for sending many parameters in the body and get a JSON response, which is the same response each time you call the POST API
@michaelcapera9769
@michaelcapera9769 3 жыл бұрын
Great vídeo !!! !!!
@muhammadusmanali7792
@muhammadusmanali7792 3 жыл бұрын
both are doing same work but.. when we call PUT request multiple time against same url & id than other requests we be ignored untils previous request response is sucessfully coming. On the otherhand POST execute all the request even if the reponse is not coming for previous request.
@mohammadjamshidi2112
@mohammadjamshidi2112 Жыл бұрын
u r amazing!
@teamniazigaming
@teamniazigaming Жыл бұрын
Post us used to store new data into database but Put is used to store new data into existing record
@akankshagautam4308
@akankshagautam4308 2 жыл бұрын
sir my put API function is working properly and the msg is also printed on postman when i'm testing the API but the problem is that the data is not updated in the database. in this case what should i d??
@sauravmishra__
@sauravmishra__ 2 жыл бұрын
I think you should check your model code.
@umranjabbar3853
@umranjabbar3853 2 жыл бұрын
my delete and put api works fine it never shows me any kind of error code working fine but recoced form database never update and deleted Final $result variable also return True value ?? Post and get work fine
@youseffathi7123
@youseffathi7123 4 жыл бұрын
I think yes you can use post to update data because it is make the same thing will send Id and name and then in your controller find the id and change name
@hesami13
@hesami13 Жыл бұрын
Sometimes, in addition to string data, you need to send files when updating data. When using apiResource in Laravel, the PUT method does not receive any data, and you have not provided a solution for this issue.
@sidohams1145
@sidohams1145 Жыл бұрын
Attempt to assign property \"name\" on null error on this video sir
@abderrahmanbouichou374
@abderrahmanbouichou374 Жыл бұрын
if any want to validate data then you must use Validator facad to create an instance for the incoming data request use Illuminate\Support\Facades\Validator; then apply this piece of code {concider changing the device,id to your table name) $validator = Validator::make($req->all(), [ 'id' => 'required|exists:devices,id', 'title' => 'required|string|max:255', 'price' => 'required|numeric', ]); then we make a costum response for when the validator fails if ($validator->fails()) { return response()->json([ 'success' => 0, 'code' => 422, // Unprocessable Entity 'message' => 'Validation failed', 'errors' => $validator->errors(), ], 422); } //the rest of the logic
@32anchalprajapati21
@32anchalprajapati21 Жыл бұрын
Hi
@joerodrigo9661
@joerodrigo9661 3 жыл бұрын
I have a question. When I use Device::find($req->id), its all working, but when I used, Device::find(['id'],$req->id), it gives me error, I tried to return the value of the latter one, still it gives me data from devices with id = 5, isn't the latter one used to specify what column to find when using the ::find(), method?
@fzumbado3k
@fzumbado3k 3 жыл бұрын
Find works on the primary key. What you are looking for maybe is Devices::where('id', $req->id)->first(); (or firstWhere() instead).
@thehien.
@thehien. 3 жыл бұрын
I don't know , why had PUT method and POST method An error occurred . even though I followed the video the error : The Get method is not supported for this route. Supported methods: PUT
@haiderazad8944
@haiderazad8944 3 жыл бұрын
Use Route::PUT(" "," "); instead of GET
@thehien.
@thehien. 3 жыл бұрын
@@haiderazad8944 thanks a lot !
@thecodes
@thecodes 3 жыл бұрын
what about if any field is null
@waseemashraf-nj9dj
@waseemashraf-nj9dj Жыл бұрын
$device->name = $request->name ?? $device->name; $device->unit_id = $request->unit_id ?? $device->unit_id; Changed my update function to this and solved the problem. It basically assigns new value only if the new value exist else we will use the old value for the field.
@nkitkanjiya7241
@nkitkanjiya7241 4 жыл бұрын
The GET method is not supported for this route. Supported methods: PUT. how to solve this
@codestepbystep
@codestepbystep 4 жыл бұрын
You are sending GEt request but your route not created for it..
@nkitkanjiya7241
@nkitkanjiya7241 4 жыл бұрын
@@codestepbystep i already created in route api , but whenever i insert data through postman it's showing errors,but when i passing statics data it's working
@negi3625
@negi3625 3 жыл бұрын
@@nkitkanjiya7241 did you get the solution of this error? i think its beacause of Request variable $req is not getting any data?Help me out
@muhammadahasan1315
@muhammadahasan1315 2 жыл бұрын
Laravel 8 tutorial -  Delete method API
6:44
Code Step By Step
Рет қаралды 26 М.
Laravel 8 tutorial -  Search API
5:58
Code Step By Step
Рет қаралды 38 М.
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 344 М.
Synyptas 4 | Арамызда бір сатқын бар ! | 4 Bolim
17:24
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 40 МЛН
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 11 МЛН
How To Make A PUT, PATCH & DELETE Request In Postman
7:23
ProgrammingKnowledge
Рет қаралды 18 М.
Laravel 8 tutorial -  API authentication with Sanctum
15:51
Code Step By Step
Рет қаралды 81 М.
Laravel 8 tutorial -  Post method API
10:31
Code Step By Step
Рет қаралды 65 М.
Laravel 8 tutorial -  API Validation
10:48
Code Step By Step
Рет қаралды 36 М.
Laravel 8 tutorial - Delete Data in Database
10:08
Code Step By Step
Рет қаралды 44 М.
Deep Dive into REST API Design and Implementation Best Practices
12:02
Software Developer Diaries
Рет қаралды 56 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 223 М.
Laravel 8 tutorial - get API with params
5:29
Code Step By Step
Рет қаралды 38 М.
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 344 М.