Edit and Delete a Record - RESTful API with Laravel - 04

  Рет қаралды 24,021

Atif Naseem

Atif Naseem

Күн бұрын

Пікірлер: 68
@SHAJ.T3CH
@SHAJ.T3CH 5 жыл бұрын
Thanks Again
@AtifNaseem
@AtifNaseem 5 жыл бұрын
My pleasure. Don't forget to like : )
@mayflower_jeme
@mayflower_jeme 5 жыл бұрын
Do we need the Request parameter in countryDelete function? Just curious because I didn't include it in mine. Thank you kindly for this straight to the point tutorial. It has helped me so much. Learnt everything I needed in under 1 hour.
@AtifNaseem
@AtifNaseem 5 жыл бұрын
You are right there is no need of Request parameter in countryDelete function because we are deleting record just by id only.
@SorrowBee_2
@SorrowBee_2 3 жыл бұрын
thanks this video helped me for the competition
@AtifNaseem
@AtifNaseem 3 жыл бұрын
Glad to hear it!
@raymondpang6707
@raymondpang6707 5 жыл бұрын
thanks guys , this tutorial is very helpful because it is straight to the point which are update and delete function .but i hope you can do another video which is talking or teaching how we use a right way and "how to handle the Exception Error" when we are connecting the frontend and backend.
@raymondpang6707
@raymondpang6707 5 жыл бұрын
by the way very thx
@AtifNaseem
@AtifNaseem 5 жыл бұрын
I will make a lecture soon. Thanks
@ashrafsayed1058
@ashrafsayed1058 3 жыл бұрын
if any one face problem with put method in update country you can use post method also it work like a charm
@AtifNaseem
@AtifNaseem 3 жыл бұрын
Thanks Ashraf Sayed
@aicreatedvideosforeveryone
@aicreatedvideosforeveryone 3 жыл бұрын
i am using laravel 8 for this examples i have to change delete and update functions as below and this worked public function countryDelete(Request $request, $id){ $country = CountryModel::find($id); $country->delete(); return response()->json(null,204); }
@AtifNaseem
@AtifNaseem 3 жыл бұрын
great
@Thisarusaduranga
@Thisarusaduranga 4 жыл бұрын
thnks for very much..
@AtifNaseem
@AtifNaseem 4 жыл бұрын
Welcome!
@tothebone4613
@tothebone4613 5 жыл бұрын
btw don't you need to set up homestead.yawl and vagrant ?,
@AtifNaseem
@AtifNaseem 5 жыл бұрын
I didnt setup at this stage.
@tothebone4613
@tothebone4613 5 жыл бұрын
@@AtifNaseem are they required for restful api ?
@AtifNaseem
@AtifNaseem 5 жыл бұрын
@@tothebone4613 No. Not necessary.
@arjunmalhotra1222
@arjunmalhotra1222 4 жыл бұрын
Thanks sir
@AtifNaseem
@AtifNaseem 4 жыл бұрын
welcome.
@alexyan7245
@alexyan7245 3 жыл бұрын
how to get auto increment id for the next post after deleted data?
@AtifNaseem
@AtifNaseem 3 жыл бұрын
you can get this in response data by adding 1 in the query (get max id of the table)
@sadidhasanrakib9271
@sadidhasanrakib9271 4 жыл бұрын
While updating, the "ID" that you have passed through api route, would not you use it to check whether the corresponding record is available or not in the database?
@AtifNaseem
@AtifNaseem 4 жыл бұрын
Actually I covered all the basics. You must implement record checking before updating and return messages accordingly.
@yasincimic1252
@yasincimic1252 3 жыл бұрын
He uses model binding.
@muaazhammad4446
@muaazhammad4446 5 жыл бұрын
i think there is no need of request parameter in delete method .... ?
@AtifNaseem
@AtifNaseem 5 жыл бұрын
Yes you are right. I didnt use it here. You can use it with any field.
@iammuttaqi
@iammuttaqi 5 жыл бұрын
why do we need to pass CountryModel in parameter where updating?
@AtifNaseem
@AtifNaseem 5 жыл бұрын
If you auto-generate resource controller using php artisan make:model -a [ModelName] then you have the update() function like below: public function update(Request $request, ModelName $model) { // } Here, Lavarel automatically fetch the Model object into $model. So, we can save the $request using the Model object $model
@melanyadavtyan4244
@melanyadavtyan4244 4 жыл бұрын
I have an error in postman The PUT method is not supported for this route. Supported methods: GET,
@AtifNaseem
@AtifNaseem 4 жыл бұрын
change Route::get to Route::put
@auscencekanhonou431
@auscencekanhonou431 4 жыл бұрын
The postman shows me Method Not Allowed The requested method PUT is not allowed for the URL /api/contry/241.
@AtifNaseem
@AtifNaseem 4 жыл бұрын
check the route. is it set to put?
@yasindemirkaya2954
@yasindemirkaya2954 4 жыл бұрын
@@AtifNaseem mine is set to put but i'm still having the same error
@namphung7592
@namphung7592 4 жыл бұрын
it return note: "Could not get any response", but the record still has deleted, and in console "Error: Parse Error", "Warning: This request did not get sent completely and might not have all the required system headers". Please help me
@AtifNaseem
@AtifNaseem 4 жыл бұрын
Did you test on postman?
@namphung7592
@namphung7592 4 жыл бұрын
@@AtifNaseem yes, i tried to fix this error but it did not work :((
@AtifNaseem
@AtifNaseem 4 жыл бұрын
I can't say anything without looking your code.
@tarunahuja3230
@tarunahuja3230 4 жыл бұрын
Delete method not working on server. Saying method not allowed laravel 7
@AtifNaseem
@AtifNaseem 4 жыл бұрын
check the request, is it GET or POST?
@bishalsubba2903
@bishalsubba2903 4 жыл бұрын
404 page not found!!whats wrong i cant figure it
@AtifNaseem
@AtifNaseem 4 жыл бұрын
is your other Laravel routes are working?
@amansayeed
@amansayeed 4 жыл бұрын
i am using taking a row _z_country first I edit using the put API then delete API same row but its not perform I am getting this error . here is the error Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`api`.`_z_address`, CONSTRAINT `_z_address_country_id_foreign` FOREIGN KEY (`country_id`) REFERENCES `_z_country` (`id`)) (SQL: delete from `_z_country` where `id` = 1) in file
@AtifNaseem
@AtifNaseem 3 жыл бұрын
It is because of Foreign Key constraint, simply delete foreign key from Mysql table or create a query to delete child first.
@ashique12009
@ashique12009 5 жыл бұрын
Here also you are not showing us your update / deleting operation code. What is coming from your request object and then how you perform your operation etc etc. Thank you.
@AtifNaseem
@AtifNaseem 5 жыл бұрын
Update and delete operation code is also showed, kindly watch all the videos from playlist.
@umermansoor3099
@umermansoor3099 5 жыл бұрын
error showing 419 page expired
@AtifNaseem
@AtifNaseem 5 жыл бұрын
It is difficult to figure out what is missing in your code. Check your code from start.
@umermansoor3099
@umermansoor3099 5 жыл бұрын
Csrf Token not defined
@AtifNaseem
@AtifNaseem 5 жыл бұрын
@@umermansoor3099 Are you using web routes?
@harrylyod3402
@harrylyod3402 4 жыл бұрын
Hi if someone is having trouble to update the data. Change the countryUpate method to : public function countryUpdate(Request $request, $id){ $country = CountryModel::find($id); $country->update($request->all()); return response()->json($country,200); }
@AtifNaseem
@AtifNaseem 4 жыл бұрын
Thank you Harry
@bishalsubba2903
@bishalsubba2903 4 жыл бұрын
still having problem ...404 page not found
@aicreatedvideosforeveryone
@aicreatedvideosforeveryone 3 жыл бұрын
Yeah this is worked for me thanks
@yasincimic1252
@yasincimic1252 3 жыл бұрын
You don't need $request paramater in countryDelete() function it could be countryDelete(Country $country);
@AtifNaseem
@AtifNaseem 3 жыл бұрын
You are right, Thanks Yasin Cimic.
@waleedraza8082
@waleedraza8082 5 жыл бұрын
not fetching data
@AtifNaseem
@AtifNaseem 5 жыл бұрын
share your errors?
@hichembed8174
@hichembed8174 4 жыл бұрын
yes it didn't fetch data in Put method so I change a little bit the code and it working public function countryUpdate(Request $request, $id) { $country = CountryModel::findOrFail($id); $country->update($request->all()); return response()->json($country, 200); }
@wildhandb
@wildhandb 4 жыл бұрын
update & delete not working on me sir, thankyou🙏🏻 # onAPI Route::put('country/{id}', 'Country\CountryController@countryUpdate'); Route::delete('country/{id}', 'Country\CountryController@countryDelete'); # onController public function countryUpdate(Request $request, CountryModel $country) { $country->update($request->all()); return response()->json($country, 200); } public function countryDelete(Request $request, CountryModel $country) { $country->delete(); return response()->json(null, 204); }
@AtifNaseem
@AtifNaseem 4 жыл бұрын
errors?
@wildhandb
@wildhandb 4 жыл бұрын
yes sir, not running anything..
@wildhandb
@wildhandb 4 жыл бұрын
@@AtifNaseem but the other method on controller CountryController still works on me
@jorgeleon9212
@jorgeleon9212 4 жыл бұрын
si jala
@AtifNaseem
@AtifNaseem 4 жыл бұрын
si jala ?
@MrFranciscoooooo
@MrFranciscoooooo 4 жыл бұрын
those methods for api are not the correct to use.. still you can have ::resource now in API to simplify the "routes"
@AtifNaseem
@AtifNaseem 4 жыл бұрын
I explained the same in the series, you will find in next videos and the reason also.
Add a Record - RESTful API with Laravel - 03
5:16
Atif Naseem
Рет қаралды 34 М.
Validation - RESTful API with Laravel - 05
9:10
Atif Naseem
Рет қаралды 25 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Resource - RESTful API with Laravel - 06
7:18
Atif Naseem
Рет қаралды 20 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 223 М.
From Laravel Blade to Vue.js + API [Live-coding Example]
22:28
Laravel Daily
Рет қаралды 169 М.
Laravel CRUD in 50 minutes for Beginners  from Scratch
49:58
Devtamin
Рет қаралды 242 М.
Securing a Laravel API in 20 minutes with JWTs
20:36
Andrew Schmelyun
Рет қаралды 79 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН