TubeSum ← Transcribe a video

Laravel 11 rest api tutorial | How to make rest API in Laravel 11 | Laravel 11 API CRUD from Scratch

Transcribed Jun 15, 2026 Watch on YouTube ↗
Beginner 12 min read For: Beginner to intermediate Laravel developers looking to build REST APIs.
48.5K
Views
818
Likes
33
Comments
26
Dislikes
1.8%
📊 Average

AI Summary

This tutorial demonstrates how to build a complete REST API in Laravel 11, covering CRUD operations for a products resource. It walks through installing the API scaffolding, creating migrations, models, controllers, and resources, and testing endpoints with Postman.

[0:00]
Introduction and Setup

The video starts with a fresh Laravel 11 installation and serves the application at localhost:8000.

[1:02]
Install API Scaffolding

Run `php artisan install:api` to install API scaffolding, which creates api.php routes, personal access token migration, and the HasApiTokens trait.

[1:45]
Add HasApiTokens Trait

Add the `HasApiTokens` trait to the User model to enable API token authentication.

[2:44]
Run Migrations

Run `php artisan migrate` to create the personal_access_tokens table in the database.

[3:06]
Create Products Migration

Create a migration for the products table with fields: name (string), price (integer), description (mediumText).

[4:13]
Create Product Model

Create the Product model and set the table name and fillable fields (name, description, price).

[5:09]
Create API Controller

Create a controller at `app/Http/Controllers/Api/ProductController.php` using `php artisan make:controller Api/ProductController`.

[5:54]
Define API Routes

Use `Route::apiResource('products', ProductController::class)` in api.php to generate RESTful routes.

[6:25]
List Routes

Run `php artisan route:list` to view all registered routes, including the API routes for products.

[7:16]
Implement Index Method

In the index method, fetch all products using `Product::get()` and return them as a JSON collection using a ProductResource.

[8:24]
Create Product Resource

Create a resource class with `php artisan make:resource ProductResource` to format JSON responses.

[10:44]
Test Index API with Postman

Test the GET /api/products endpoint in Postman. Initially returns empty array, then after adding count check returns 'No record available'.

[12:32]
Implement Store Method with Validation

In the store method, validate input using Validator facade. If validation fails, return 422 with error messages. On success, create product and return success response.

[15:44]
Test Store API with Postman

Test POST /api/products with JSON body. Initially fails due to validation, then after fixing validator, successfully creates a product.

[19:30]
Implement Show Method

In the show method, use route model binding to fetch a single product by ID and return it using ProductResource.

[20:37]
Test Show API with Postman

Test GET /api/products/{id} with ID 1, returns the product data. Also adds more products (mango, grapes) for testing.

[22:04]
Implement Update Method

In the update method, validate input, update the product using `$product->update($request->all())`, and return success response with updated data.

[24:08]
Test Update API with Postman

Test PUT /api/products/{id} with ID 3, updates grape name and price successfully.

[25:35]
Implement Destroy Method

In the destroy method, delete the product using `$product->delete()` and return success message.

[26:45]
Test Destroy API with Postman

Test DELETE /api/products/{id} with ID 3, deletes the product. Then trying to fetch ID 3 returns 404 error.

[27:46]
Handle 404 Errors Gracefully

Modify `bootstrap/app.php` to render a JSON response for ModelNotFoundException, returning 'Record not found' instead of HTML error.

[28:37]
Final Verification

After handling 404, fetch all products again to confirm deletion. Only ID 1 and 2 remain.

The tutorial successfully demonstrates building a complete RESTful API in Laravel 11 with CRUD operations using API resource routes, validation, and JSON resources. The next video will cover authentication to secure the API routes.

Clickbait Check

90% Legit

"Title accurately describes the tutorial content: building a REST API in Laravel 11 from scratch with CRUD operations."

Mentioned in this Video

Tutorial Checklist

1 1:02 Run `php artisan install:api` to install API scaffolding.
2 1:45 Add `HasApiTokens` trait to User model.
3 2:44 Run `php artisan migrate` to create personal_access_tokens table.
4 3:06 Create migration for products table: `php artisan make:migration create_products_table`.
5 3:36 Add fields to migration: name (string), price (integer), description (mediumText).
6 3:55 Run `php artisan migrate` to create products table.
7 4:13 Create Product model: `php artisan make:model Product`.
8 4:36 In Product model, set `$table = 'products'` and `$fillable = ['name', 'description', 'price']`.
9 5:09 Create API controller: `php artisan make:controller Api/ProductController`.
10 5:54 In routes/api.php, add `Route::apiResource('products', ProductController::class)`.
11 6:25 Run `php artisan route:list` to verify routes.
12 7:16 In ProductController, implement index method: fetch all products and return collection using ProductResource.
13 8:24 Create ProductResource: `php artisan make:resource ProductResource`.
14 9:00 In ProductResource, define fields to return (id, name, description, price, created_at).
15 12:32 Implement store method with validation using Validator facade.
16 14:00 In store method, on success create product and return ProductResource with success message.
17 19:30 Implement show method with route model binding: return ProductResource for the product.
18 22:04 Implement update method: validate input, call `$product->update()`, return updated ProductResource.
19 25:35 Implement destroy method: call `$product->delete()`, return success message.
20 27:46 In bootstrap/app.php, add exception handling for ModelNotFoundException to return JSON error.

Study Flashcards (11)

What command installs API scaffolding in Laravel 11?

easy Click to reveal answer

php artisan install:api

1:02

Which trait must be added to the User model for API token authentication?

easy Click to reveal answer

HasApiTokens

1:45

What command creates a resource controller for an API?

medium Click to reveal answer

php artisan make:controller Api/ProductController

5:09

How do you define a RESTful API resource route for products?

medium Click to reveal answer

Route::apiResource('products', ProductController::class)

5:54

What command lists all registered routes?

easy Click to reveal answer

php artisan route:list

6:25

What is the purpose of a resource class in Laravel?

medium Click to reveal answer

To format JSON responses and control which fields are returned.

8:24

How do you return a collection of models using a resource?

hard Click to reveal answer

ProductResource::collection($products)

9:00

What HTTP status code is typically returned for validation errors?

medium Click to reveal answer

422

17:29

How do you enable route model binding in a controller method?

hard Click to reveal answer

Type-hint the model and variable name matching the route parameter, e.g., `Product $product`.

19:30

What method is used to delete a model instance?

easy Click to reveal answer

delete()

26:21

How do you customize the 404 response for API routes?

hard Click to reveal answer

Modify bootstrap/app.php to handle ModelNotFoundException and return a JSON response.

27:46

💡 Key Takeaways

🔧

Install API Scaffolding

Key first step to enable API functionality in Laravel 11.

1:02
🔧

API Resource Routes

Using apiResource automatically generates all CRUD routes with proper HTTP verbs.

5:54
🔧

Resource Classes for JSON

Resources provide a clean way to transform models into JSON responses.

8:24
🔧

Validation with Validator Facade

Demonstrates proper API validation and error response with 422 status.

12:32
🔧

Custom 404 Handling

Shows how to return JSON error for not found models instead of HTML.

27:46

✂️ Creator Tools: Viral Hooks

AI-generated clip ideas for Shorts based on the transcript

Laravel 11 REST API: No api.php? No Problem!

45s

Shows the surprising absence of api.php in Laravel 11, hooking developers who expect it.

▶ Play Clip

Install Laravel 11 API Scaffold in 1 Command

50s

Quick, satisfying demo of 'php artisan install:api' that instantly adds API structure.

▶ Play Clip

Laravel 11 API: First POST Request Fails!

50s

Shows a common validation error and its fix, relatable to beginners.

▶ Play Clip

Laravel 11: Delete API Record in 2 Lines

50s

Demonstrates the simplicity of deleting records, appealing to efficiency seekers.

▶ Play Clip

Fix Laravel 11 404 Error for Deleted API Records

50s

Shows how to return a proper JSON error instead of HTML, a common pain point.

▶ Play Clip

[00:00] hey guys welcome back so guys in this

[00:02] video we are going to learn the complete

[00:05] rest API in larl 11 version so guys I

[00:09] have already installed a fresh laral 11

[00:11] application here and and also served the

[00:15] application at Local Host 8000 which is

[00:18] running over here okay so now guys let's

[00:21] get started so let's open our project in

[00:23] our editor so I use vs code editor so

[00:27] first step uh after installing your

[00:29] larel project

[00:30] let's install the API also so let's open

[00:34] the terminal and click on new terminal

[00:36] so before installing I just want to show

[00:38] you few things like here routes so in

[00:40] this routes you see you don't find

[00:42] api.php file and inside your database

[00:46] you don't find few migration about the

[00:48] API personal access token and also guys

[00:52] about the model so in the model user.php

[00:55] you don't have a trade called has API

[00:59] token okay so guys now let me

[01:02] just get started with installation PHP

[01:06] Artis install colon API hit enter so

[01:10] your installation

[01:18] starts so guys our installation is

[01:21] completed and here it's asking a

[01:23] question like new database migration has

[01:25] been published would you like to run all

[01:28] the pending migration files yes or no so

[01:31] right now we'll give no guys because we

[01:33] want to see our database connected or

[01:35] not and here you see API scaffolding

[01:39] installed please add the has API token

[01:43] trade to your user model okay so make

[01:45] sure you're copying this now let's

[01:47] minimize the terminal and first let us

[01:50] go to your app model user.php inside the

[01:55] user model we have to add this has API

[01:58] token

[02:00] so let us give as use now you can copy

[02:03] this at the last of your use inside the

[02:06] class user model you have to add this

[02:09] has API token perfect so now guys uh we

[02:12] have added the has API token and now

[02:15] let's move in the migration so database

[02:18] migration you find the new table about

[02:22] personal access token okay and also

[02:24] you'll see a new file inside the routes

[02:28] api.php

[02:29] cool so now guys let's migrate that so

[02:33] before migrating please check do you

[02:35] have connected your database or not so

[02:37] yes I have connected here using MySQL

[02:40] and larel 11 database so now guys let's

[02:44] hit the command PHP rtis migrate hit

[02:47] enter and your table is

[02:51] migrated now let us get back and see do

[02:56] we have a personal access token table

[02:58] here so let's refresh so guys here you

[03:02] see we have a personal access token

[03:04] table okay so now so first step guys we

[03:06] are going to start with the API CED

[03:09] operation with an example of products so

[03:11] let's create a migration file named

[03:14] products the HP Artis make colon

[03:19] migration

[03:20] create products table hit enter and here

[03:25] migration is created now you can go to

[03:28] database migration and the last and now

[03:32] let's give the fields so we'll give a

[03:36] string the product

[03:38] name then the product price and one more

[03:42] field let's add that as a medium

[03:48] text text function which will be

[03:52] description okay and now let's push this

[03:55] table into our database so PHP Artisan

[03:59] my

[04:00] hit enter it's migrated now you can find

[04:03] that products table Let me refresh the

[04:06] table here okay products table cool so

[04:09] we have migrated it now we can get back

[04:13] and let's create the model so PHP

[04:15] artison makeen model the model name will

[04:18] be product hit enter so our model also

[04:23] is created product.php let me close

[04:27] this and go to app model your

[04:31] product.php

[04:33] perfect let me just zoom it so first

[04:36] step guys we will declare the table like

[04:38] product table equal to your table name

[04:42] products is the table name and then

[04:44] protected dollar

[04:47] fillable will be all the fields so what

[04:51] are the fields you can just copy from

[04:53] your migration

[04:55] file that is named description and price

[04:59] let's close

[05:02] name

[05:04] description

[05:06] price that's it and now let's create One

[05:09] controller so PHP Artis make colon

[05:13] controller and I want to create this

[05:16] controller inside a API folder API SL

[05:22] product controller hit enter and your

[05:26] controller is created so you can find

[05:28] that in app HTTP controller uh API

[05:31] folder inside that API folder you find

[05:34] your product controller cool so now guys

[05:37] let's begin with creating the functions

[05:39] like public function the function name

[05:42] index function and here is a typo so in

[05:46] this index function we will get all the

[05:48] records of the product so before getting

[05:51] the records we have to create the API so

[05:54] let us go to our routes api.php and here

[05:59] let's let begin so first step guys we

[06:01] are going to create a route using API

[06:04] resource route okay so now guys let us

[06:08] give

[06:09] the URL so creating a route products and

[06:13] let's mention the

[06:15] product controller colon colon class so

[06:19] make sure you're importing the class

[06:20] guys which is already imported

[06:23] automatically and now guys we can uh

[06:25] check the route list for this product so

[06:28] let me open the terminal PHP Artisan

[06:33] route colon list hit enter so let's move

[06:38] out the top and here you see the API

[06:41] part okay so this will be our complete

[06:45] API route so now guys we can just follow

[06:49] this and create the complete

[06:52] functions so let's move inside the

[06:54] product

[06:55] controller copy

[06:57] this create for the store

[07:01] and for the

[07:06] show and

[07:09] update and then

[07:14] destroy that's it so now guys let's

[07:16] begin with the index function so first

[07:19] let's create a variable called

[07:21] products equal to your product model

[07:24] colon colon get function okay so getting

[07:28] all the product data

[07:30] and import the product class so it's

[07:33] imported here guys and now let us return

[07:36] this in jsn format so first I will check

[07:40] if there is

[07:42] records like

[07:44] yes

[07:47] else so if a record is available then

[07:50] show else you can

[07:52] return response function in JSO n

[07:58] format and reply 200

[08:01] here and give the message

[08:05] as um no

[08:09] record available okay so if the record

[08:13] is found then we are going to return the

[08:16] Complete product data so how are you

[08:18] going to return guys we will be using

[08:20] the resource part so let me just a new

[08:24] terminal and create a new resource PHP

[08:28] Artis

[08:30] makeon resource

[08:33] the product resource okay hit enter and

[08:38] your resource will be created so you can

[08:40] find that in the app HTTP directly

[08:44] resources folder will be created and

[08:46] here is your product resource so guys

[08:49] this resources is used to respond in

[08:51] Json format okay so here you see Json

[08:55] resources it uses so guys now you can

[08:58] use this

[09:00] product resource so you are sending

[09:04] multiple data so you have to use in

[09:06] different way like just return product

[09:09] resources colon colon

[09:11] collection function and inside this you

[09:13] paste this product variable directly

[09:16] okay so whatever data you have in this

[09:19] you can access each column so before

[09:22] that let me import this class okay we

[09:24] have imported and now guys all the

[09:26] column Fields like name description and

[09:29] price at this product you can access in

[09:31] this product resources so right now you

[09:34] see here that it's returned directly

[09:37] parent to array so instead of this you

[09:39] can return in this format

[09:42] also like the

[09:45] name of dollar this of name okay so same

[09:51] way guys you have to change for the

[09:53] description

[09:56] description then price if if you want to

[09:59] take the created at column so you can

[10:02] take it same way created

[10:06] at

[10:08] Price description and if you want to

[10:10] give name or else

[10:13] product name so anyhow it depends on you

[10:16] so this will be the response output okay

[10:19] okay so let me just keep it name itself

[10:22] and we can get the ID

[10:25] also done so guys the difference is here

[10:29] you can can manage only like what Fields

[10:31] you want to show or else if you want to

[10:33] show complete thing you can just keep

[10:35] the same okay so guys I will prefer

[10:38] using like this so now let's get back

[10:41] and yep so guys let us test this API

[10:44] like this index function part so let's

[10:47] go to our api.php and to test this API

[10:50] I'm using a postman software so let me

[10:53] just open so guys this is a postman

[10:56] software which I have installed so now

[10:58] guys let's make make a new request here

[11:00] just click on this plus icon and here

[11:02] your request sends so now guys let us

[11:04] copy the API get back and by default you

[11:08] have to give API and then products so

[11:11] what is the complete URL guys let us go

[11:14] to our browser just copy this Local Host

[11:17] 8,000 and paste

[11:19] here let me remove this extra forward

[11:22] slash and let's send the request so if

[11:25] you send so let's see what happens now

[11:28] so here we get at the error guys like

[11:33] raw so internal server error which is

[11:36] telling the collect function does not

[11:40] exist so it's not collect it's

[11:42] collection guys so let's go back to

[11:46] our index function and tell

[11:49] collection and now get back send the

[11:52] request and here you see by default data

[11:56] has come okay now you can click on this

[11:58] pretty so here you see in the object

[12:01] data you are getting this empty array so

[12:04] guys here it's not able to check like it

[12:07] has data or not so you can use just

[12:09] count function if it is greater than

[12:11] zero then you have to return this else

[12:14] return this so now get back again send

[12:17] the request so here you see the message

[12:19] no record available and the status is

[12:22] 200 so you can see at this okay so now

[12:26] guys uh let us get back and and start

[12:29] with inserting the record using the API

[12:32] so it is very simple guys just use a

[12:34] simple request here get the request

[12:36] dollar request and do the validation

[12:40] first request of

[12:42] validate function and use the name field

[12:50] okay this will be your input field value

[12:52] and what will be the validation it is

[12:56] required and it's going to be a string

[12:59] value and then Max

[13:02] 255 same way for

[13:05] the price will be integer and you can

[13:08] remove this

[13:10] Max so this will be the price and for

[13:13] the

[13:15] description it is required string and

[13:17] Max should not be there okay so now guys

[13:21] you can get started with inserting the

[13:23] record into your model I mean product

[13:25] table so let's use product model colon

[13:29] colon create function in Array format

[13:33] and you get all this each Fields so let

[13:37] me just copy and paste here and insert

[13:40] this just get the

[13:43] request

[13:44] of name okay so this will be a name

[13:48] description so you have to just paste

[13:50] that let's paste here paste it so my

[13:55] input request description and input

[13:58] price so once product is created you

[14:01] have to send let's response so return

[14:04] response function in JS n

[14:08] format in

[14:10] Array 200 and here array will be like

[14:15] message

[14:17] of product

[14:20] created successfully and also you can

[14:24] respond the data guys which

[14:27] is the

[14:30] dollar product equal to Dollar product

[14:33] okay and here you set the

[14:37] data instead of sending the complete

[14:39] model we want to send our format data so

[14:42] which is the product resource so let's

[14:45] get back on this let's copy the product

[14:49] resource

[14:51] and make as new product resource

[14:55] function okay so now guys let's get back

[14:58] and create a product record so let me

[15:02] just copy this complete API and paste

[15:05] here so guys to create or insert the

[15:08] record you have to use the same route

[15:10] which is shown here let me just show you

[15:12] in

[15:14] the route list so here you see guys that

[15:17] is about the post request which is

[15:19] product. store it goes to the store

[15:21] function and this is the API so using

[15:24] post method and the API stat so now guys

[15:27] let's get back to our Postman

[15:30] and yep so this will be the API and it

[15:33] is a post request so let us select that

[15:35] post method and now guys let's go on the

[15:38] body Tab and here you have to select

[15:40] with form data or raw data okay so now

[15:44] guys let's add the fields so make sure

[15:47] this raw data which you are entering it

[15:50] should be in jsn format so select the

[15:52] jsn format here first and then you can

[15:54] work on it so now guys let's add the

[15:57] fields like name colon and here I'll

[16:00] give null and the field

[16:05] description description colon null and

[16:09] finally the field price colon

[16:13] null okay so now guys let us uh just

[16:16] click to send the request what happens

[16:18] now if you click

[16:20] Send uh here you get an error like let

[16:23] me just click on preview so here you see

[16:25] guys that is it is showing the main page

[16:27] homepage so I think it's not able to

[16:30] handle the validation part so let us get

[16:33] back and move at the store function at

[16:37] validate code so instead of this

[16:40] validation we'll be using a validator

[16:42] method so let's create a variable called

[16:45] validator equal to your

[16:49] validator class colon colon make

[16:51] function and inside this function you

[16:54] have to pass dollar request of all

[16:57] function and then use array and give all

[17:00] the input Fields so here you just copy

[17:03] and paste the

[17:05] fields and yep so now you can remove

[17:09] this now let's copy this

[17:14] validator

[17:16] if

[17:19] validator fails

[17:22] function then just return response

[17:26] function in JSO n

[17:29] format and the error will be

[17:32] 422 so in this uh you can send the

[17:36] validator messages so let me copy this

[17:39] variable and mention that error then

[17:43] Arrow function dollar validator of me S

[17:46] AES messages function okay and if you

[17:50] want to mention like the

[17:55] message

[17:57] uh all

[17:59] Fields fields are

[18:02] mandatory okay and now guys uh import

[18:05] this valid data class so class import so

[18:09] here you select with eliminate support

[18:11] fets valid data let's click on it and

[18:14] yep so you can just

[18:16] move and update that valid dator okay so

[18:19] here our valid dator is imported perfect

[18:23] so now guys let's get back to our

[18:24] Postman and send the request again so

[18:27] here all the fields are empty right now

[18:30] let's click to send the request so here

[18:32] you see all fields are mandatory the

[18:34] message is and the error inside that it

[18:37] is showing name field is required

[18:39] description required price is required

[18:41] so let us add the product like

[18:45] apple and this is Apple

[18:50] description and I will keep the price

[18:52] empty let's send a request so you see

[18:55] again that it is asking for the price

[18:57] field and now if I give

[18:59] like 250 and let's click to send the

[19:02] request so here you see the product

[19:05] created successfully and this is the

[19:07] data guys okay which is just shown only

[19:10] whatever Fields you want so now guys let

[19:12] me just show you in the database whether

[19:14] it is stored or not perfect so here you

[19:16] see guys our record is stored and now

[19:19] guys let's get back to the editor and so

[19:23] we have done with the create product and

[19:25] now let's move on to view the product I

[19:27] mean fetch each product so for that

[19:30] let's get back to the api.php and this

[19:33] is the API resources guys and according

[19:35] to this to get the data one data you

[19:38] have to use this route so which is

[19:41] coming via show method so here is the

[19:45] show method with the product product ID

[19:49] and using a get method okay so what you

[19:51] have to do you have to use this product

[19:54] product variable inside your controller

[19:56] so let's copy this product and get back

[19:58] inside your show function and here

[20:02] provide the model name product and then

[20:06] the product variable so make sure this

[20:08] variable is same as provided in your

[20:10] route list so this is the variable guys

[20:13] product so I'm pasting that product so

[20:15] now let's return this so return inside a

[20:19] gson format you can return or else with

[20:21] the help of your resource that is your

[20:24] product resource you can just use this

[20:26] and return it okay so it's the same

[20:28] logic guys returning with the status 200

[20:30] with the your field data okay product

[20:34] datas so it's the same so now guys let's

[20:37] save and yep let's go to the postman

[20:41] let's click on new tab for the new

[20:42] request and copy the API so let me just

[20:46] copy this get back and paste Here and

[20:49] Now guys the route is like providing the

[20:52] ID so ID number one here okay so now

[20:55] guys let's click to send the request so

[20:58] here here you see you have got the data

[21:00] that is id1 and the details so let me

[21:03] just add few more products okay so here

[21:07] I will add like M mango this

[21:12] is mango

[21:14] description and the price is like 150

[21:18] and let's send the request to save it so

[21:20] here product created successfully with

[21:23] the mango details and let's with the

[21:25] gpes grapes G PES grapes and this is

[21:30] going to be like 100 let's send the

[21:34] request so here we are so product

[21:38] created and now let's get back to the

[21:41] show detail okay so let's send the

[21:43] request here once again and with the ID

[21:46] one so let me get the Grim item so

[21:50] product let's send and here you see for

[21:54] the ID number three we have got the

[21:56] grapes perfect so this is how we work to

[21:59] get the data okay so now let's get back

[22:02] and continue with the update part so how

[22:04] do you update this details okay so you

[22:07] want to update this graes record so for

[22:09] that uh let us get back to the code and

[22:13] write the code for update the product so

[22:17] for that guys according to this API you

[22:19] are using uput or patch method and here

[22:22] is the variable that is product which

[22:24] goes to the update function so let us

[22:28] get the product variable I mean product

[22:32] model and dollar product variable okay

[22:35] so this is the same variable you are

[22:36] getting it and also we need the request

[22:39] like we are sending the input request

[22:41] from this Postman right so to get that

[22:45] please add the request also request of

[22:49] dollar

[22:50] request comma

[22:53] done and then guys let us add the

[22:55] validation and the update code and then

[22:58] return

[22:59] the data so let us move at the top at

[23:02] the store function so here we have

[23:04] already written the code for the

[23:07] validation and then create and then the

[23:10] response so let us copy this complete

[23:12] code and paste in the update function so

[23:16] now uh let me just arrange it here it's

[23:19] gone

[23:23] messy okay so guys First Step uh doing

[23:26] the validation let me close this

[23:28] terminal so we are doing the validation

[23:31] and responding that all fields are

[23:34] required if validation is done then you

[23:37] will start with the update part so here

[23:40] I'm just going to remove this complete

[23:41] model and just use update function

[23:45] that's it okay so this is the variable

[23:47] guys from the update function you are

[23:49] getting the product variable so using

[23:51] that product variable you are updating

[23:53] that particular record and this will be

[23:55] the

[23:56] fields cool so now guys once once

[23:58] updated you will return that product

[24:01] updated successfully and return the

[24:05] updated record okay that's it so now

[24:08] guys let us get back to the

[24:13] postman and yep let's open a new

[24:17] request and let me copy the

[24:20] API so here we paste and what method you

[24:24] have to use you have to use the put

[24:26] method so let me just show you put or

[24:28] patch any of this method you have to

[24:31] use and let's use it put method itself

[24:35] so you are using the put method and now

[24:37] get to the body part and at this body

[24:40] you have to select with the form data or

[24:43] raw data anyhow so if you are selecting

[24:45] a raw data please select this in Json

[24:47] format and provide the fields so let me

[24:50] just copy from the post request guys so

[24:53] we have already typed it let me just

[24:55] copy this and paste here okay so on this

[24:59] ID number three I want to update this

[25:01] grapes to g r a p e grape okay and here

[25:07] also grape and this is grape only we'll

[25:11] keep let's send the request so let's see

[25:14] what happens send in the request and

[25:16] here you see product updated

[25:18] successfully and the grape spelling is

[25:21] changed okay so let me just show you

[25:24] again with the pricing like I will keep

[25:26] 50 send the request and here you you see

[25:29] the data is price 50 so guys we have

[25:32] done with the updation part also cool so

[25:35] now guys let's begin with the last

[25:37] option that is destroy which means

[25:39] deleting the record using the API so let

[25:43] us get back to our code and this is our

[25:46] public function destroy function and in

[25:48] this destroy function how you can use

[25:50] please check out your route so here you

[25:52] see it is using a method delete and the

[25:55] API is same like as we edit upd dat so

[25:59] same way you can delete Also let's call

[26:01] the product model P doct product model

[26:05] dollar

[26:07] product so from where are you copying

[26:10] this variable product so here is the

[26:13] product variable guys just copy this and

[26:15] paste here and it going to the destroy

[26:18] function so now let's use this

[26:21] product and use delete

[26:24] method that's it so this will delete the

[26:27] record and then you have to return a

[26:29] message so let me just copy from above

[26:32] and paste here and here we don't need to

[26:34] show the data because we have deleted it

[26:37] so let's mention the message as deleted

[26:41] successfully okay so now guys uh let us

[26:45] get back to the postman and let's copy

[26:48] this

[26:49] API get to the new request paste it and

[26:54] please select the delete method so using

[26:57] this delete method and sending the

[27:00] request with the ID3 I want to delete

[27:03] the ID3 data and now let's click to send

[27:05] so once you click to send it will delete

[27:07] the record so let's click on send so

[27:10] here you see product deleted

[27:12] successfully and if you try to get the

[27:14] record with the ID3 you'll not be able

[27:17] to get because it's already deleted so

[27:19] let us see that let me just move to the

[27:21] third tab here which is using a get

[27:24] request and this is the ID3 let's click

[27:27] to send so here you see we have got the

[27:30] response guys and let me just preview

[27:32] here you see that 4 not4 perfect so here

[27:35] you see that 4 not4 means it's not found

[27:38] so ID3 is not found but guys this is not

[27:41] the correct way to show the output

[27:44] because it is a API request so for that

[27:46] guys you have to just add a simple code

[27:48] inside your uh go to bootstrap inside

[27:51] this bootstrap app.php and inside this

[27:54] app.php with exceptions so let's go to

[27:58] the larel documentation on error

[28:01] handling so here I found that how we can

[28:04] skip this so just copy this code guys

[28:07] and paste inside this exception part

[28:10] okay and also import this not found HTTP

[28:14] exception and also the request classes

[28:16] so here it is let us just copy this

[28:19] contrl C and import or paste at the top

[28:23] that's it now done so guys let us close

[28:26] this app.php and get back to your

[28:28] Postman and send the request again let's

[28:31] click to send so here you see message

[28:34] record not font cool so guys let us just

[28:37] get to the first uh request that is

[28:39] fetching all the products so let's fetch

[28:42] so here you see that on this request you

[28:45] have got all the products so ID one and

[28:47] id2 that is Apple and mango product

[28:50] third product is deleted

[28:53] okay so guys we have successfully

[28:55] completed with the restful API crowd

[28:58] operations using the API resource route

[29:02] okay so guys in next video we'll be

[29:03] seeing about how to create

[29:06] authentication for this route and secure

[29:08] this route so guys in this video that's

[29:10] it thank you for watching this video

[29:12] please subscribe like and share

⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.