---
title: 'Simple CRUD API | Laravel API for Beginners #2'
source: 'https://youtube.com/watch?v=BrEnMb4VWjw'
video_id: 'BrEnMb4VWjw'
date: 2026-06-15
duration_sec: 0
---

# Simple CRUD API | Laravel API for Beginners #2

> Source: [Simple CRUD API | Laravel API for Beginners #2](https://youtube.com/watch?v=BrEnMb4VWjw)

## Summary

This tutorial demonstrates building a full set of CRUD APIs for Laravel's default User model, covering create, read, update, and delete operations with HTTP methods and route conventions.

### Key Points

- **Project Overview** [00:00] — Building CRUD APIs for Laravel's default User model: create, get, update, get all, and delete.
- **Create User Route** [00:44] — Define a POST route to '/api/users' with an inline function that uses the User model's create method.
- **Testing with Postman** [03:32] — Use Postman to test the API by sending a POST request with name, email, and password; Laravel returns JSON with a 201 status code.
- **Get Single User** [06:33] — Define a GET route to '/api/users/{user}' using route model binding to automatically fetch and return the user.
- **Update User** [09:00] — Use a PATCH request to the same URL, calling the update method on the user model with the request data.
- **Get All Users** [12:03] — Define a GET route to '/api/users' and return User::all() (note: pagination recommended for production).
- **Delete User** [13:59] — Use a DELETE request to '/api/users/{user}', call delete() on the model, and return response()->noContent() (204 status).
- **Custom Route Key** [16:38] — Override the default ID lookup by specifying a custom column (e.g., email) in the route definition: Route::get('/users/{user:email}', ...).

### Conclusion

Laravel makes CRUD API creation straightforward with built-in features like route model binding and automatic JSON responses, but additional concerns like validation and pagination should be addressed for production readiness.

## Transcript

Hey, welcome back. So on this episode,
we are going to be building a full set
of CRO APIs for the user model that
comes with Laravel by default. So we're
going to have a create user, get user,
update user, uh get all users, and
delete user API. So I have selected the
user model to for today's video. Uh but
you can actually go ahead and use any
other model that you have on your
project. The reason I chose the user
model is because it ships with Larville.
So if you create a new project, you
should by default always have this users
model and table. So that's why I
selected it. But if you have an existing
model, uh you can use it and follow
along. The process should be basically
the same.
Okay guys, so first up, we're going to
start off with the create user route. So
what you need to do is define a simple
route the same way you usually do. Now
for create APIs the general convention
is to use a post request or HTTP post
request. So that's what we are going to
do. So I'm just going to type in post. I
will later on have a video on REST API.
So I'll go a little bit more in depth
into the general conventions for REST
APIs. But in this video I'm going to
keep it relatively simple. Next up we
need to define the URL for our post API.
So the convention in the Laro community
and also for REST APIs is you're going
to have your resource name. So in this
case it's going to be our model name
which is user and then we're going to
have it be plural. So it's going to be
users. And that's it. That's the URL.
And now we can go ahead and either
define your controller or in this case
I'm going to have an inline function
anonymous function just to keep it
simple for the sake of time. And last
but not least, because we are going to
be basically passing some data, I'm
going to define the request in my
function definition as well. All right.
So now that we have our API, the next
step for us is actually to create a new
user. And this is very simple to do.
This is basically laral eloquent. Uh so
we can go ahead and say user equals
our model name. So in this case I'm
going to be importing app models user.
So I do have autoimp import on my ID
setup. So if you guys see me quickly
type these in. Usually I am importing
them but they are like autoimp imported.
So as you can see it got imported over
here. So make sure you have done that.
And now we can just go ahead and call
the create method on the model.
Okay let's quickly do that. And I'm
going to pass in some data. So the
default loable user model needs the
name. So I'm going to pass in request
name. So we need to make sure we always
pass this.
Next up we are going to have email. So
I'm going to say request
email.
So this will be passed in the HTTP post
body.
And last but not least, we need
password.
So for the password I'm just going to go
ahead and use the loable hash facade. So
we can say hash make and just pass in
this password field. Now we don't have
any validation at the moment. So
technically all of these could be empty.
We're going to cover validation on a
separate video. So for now we assume the
client will always pass these values.
So, so now that we have created our
user, the only step left for us is to
actually go ahead and return the user.
That is it guys. So, we have created our
first post or create API. So, how do we
actually go ahead and test this out?
Now, for testing purposes guys, you can
do it from your terminal. If you know
how to use curl, you can go ahead and
use curl. Curl is a little bit difficult
to use. So, many people might not be
familiar with it and it's not very
visually appealing. So generally what
most people do is they use a different
software
for example something called like
Postman and they use this tool to test
their APIs. Now there are other tools
like Obsidian. There is another one
called I think HTTP PI this one and many
others. You can also install extensions
on VS code or I think if you use uh Jet
Brains or different IDs they should also
have that. So, I'll leave that to you
guys which one you prefer. For me
personally, I have used Postman for many
years. So, that's what I'm most
comfortable with. And I'm going to be
using Postman. But there is no specific
one. You can use any of them that you
like. So, I'm going to go ahead and add
our local host URL. Last but not least,
we need API and then users because
that's what we defined in our URL here,
right? And then I need to now pass name,
email, and password. So let's go ahead
and do that. I already had these done
because I was testing it, but we can say
name. I'm going to say hello world. For
email, I'm going to say YouTube at
test.com.
And for password, I'm just going to put
some random characters.
So for the request type, again, we also
need to make sure this is post. So for
example, if I put I don't know delete
and I hit send, it's going to say method
not allowed because we still we haven't
created it. So it needs to exactly match
what we have defined. So I'm going to
set post and click send.
And voila, we have created our first
successful post API. So it is now
returning the user as well. And if you
guys notice, it's actually already
formatted into JSON. So Larl is very
nice. it automatically formats
everything for us. So it's very nice and
clean. We don't actually need to
manually
uh return the response in JSON. We just
pass it the model and lot handles the
rest for us. One more thing I want you
guys to pay attention is if you look at
our uh API status code response code it
is going to be 2011. So 2011 uh
corresponds for a new record created
right. So Lable actually also
automatically handles that. So if you
return your model and it was just
created, it will actually have a 2011
status code. Okay, so that's also very
nice. We don't need to worry about the
status code. I will have a separate
video for handling different status
codes, but for now, Laravel makes this
super super easy for us. All right. So
now that we have created our first API,
let's go ahead and create the next one,
which is going to be get a single user.
This one, very similar process, guys.
Again we need to define a route for get
request or get users. It is going to be
a get http get request. Now for the URL
it still follows a similar format where
we have the model name followed with you
know an s plural. So it's going to be
users but then we are going to pass in
the unique identifier for that user as
the second part of the URL. Right? So
this part for this part we can go ahead
and use the loable uh route model
binding. So I'm going to have like a
dynamic
URL here. I'm going to say user
and I'm going to quickly define our
function here as well. So I'm going to
say function
and we can go ahead and use ludable's
route model binding. So we can say user
user and a lot of will automatically if
we for example pass in a user ID go
ahead and find that user and injected
here right so with route model binding
and actually it's very easy we can just
return user that's it that's all we have
to do so this is our get user API so
just the oneliner in loable so let's go
ahead and test this one out as well uh
I'm going to go ahead and open Postman
uh I'll save this one as create user. So
I'll save it and I'm going to create a
new one. So let me copy it.
So the URL is going to be API users and
then followed with our users ID. All
right. So let me zoom in a bit more so
it's easier for you guys to see. So this
user's ID was 13. So I'm going to put in
13. Hit send. And as you can see this
API is also working. Uh also one more
thing to pay attention guys. As you can
see this one has a 200 API. So this is
okay API while our create request had a
2011. Right? So we didn't need to worry
about the status code. A lot just
handles it for us out the box. Uh which
is very nice and kind of saves you quite
a bit of time and you don't need to
worry about them. So I'm going to save
this one as well. I'm going to say get
user API.
Uh let me save that.
Okay. So let's go ahead and create the
next API which is update user. Now for
update operations there is two types of
HTTP request we can use. We can use
either patch or put. Now there are quite
small differences between the two. So
the general difference is going to be
with patch you're going to be updating
you're going to be doing a partial
update and with a put you're going to be
performing a full replace or full update
of the resource. Now that's very
oversimplified. There are a lot more
differences. So I'm not going to be
covering all of that on today's video
because I think it requires its own
video.
But for now I'm going to be using a
patch because I'm going to be partially
updating the user. I'm going to be only
updating their name. So this one also is
going to be very similar. It will
actually follow the same URL as our get
request but just have a different
request type. So I'm going to copy this
put here and let me put this above it.
But instead of a get HTTP request, we're
going to have a patch, right? But the
URL is actually going to be identical,
right? So same URL.
Now, how do we update the user? In this
case, it's also the same. We can go
ahead and say user
update
and the usage is similar to this create.
So I'm just going to actually copy it
from the create at the top and we can
pass in the fields we want to update. So
I'm going to pass it in name.
Now you see here it says request is not
accessible. So we need to also define
the request in our method. So I'm going
to go ahead and put it here as well. And
now we have this request as well. So
this is our update. And after we have
done the update,
we can go ahead and return the user back
to the client. So I'm going to go ahead
and save this one as well, guys. Let's
go back and test this API as well.
So I'm going to create a new request.
I'll copy our get request URL.
and replace this get with a patch.
And now we need to pass in a new name.
So the previous name was hello world.
I'm going to rename it to hello
YouTube.
By the way guys, when you're using
Laravel, you can put your uh data both
in HD params and the body. Both should
work, but Larl is quite flexible. It
handles both cases. So, I'm going to be
using query paramounts because it's a
bit easier for me to add on the video.
So, I'm going to hit send.
And as you guys can see, we now get
hello YouTube. And to just double
confirm, if we go back to our get
request and hit send, we get hello
YouTube. So, the update was successful
as well.
All right. Now next to up to the next
API which is going to be get all users.
Uh you guys probably can guess this one
is going to be also quite similar. So
for the get all users
I'm going to copy the existing get user
we had. So let me define it under here.
So for the URL because we're getting all
users we obviously are not going to have
this second part. So I'm going to remove
it. And the general convention is you
just basically have your resource name
followed by an s plurals and that's your
URL. Of course, we are not no longer
doing route model binding. So this one
we also don't need. And we can just say
return user
all.
Uh obviously one question you might have
well this isn't very efficient right? If
you have like thousands of users, this
will be very slow or like crash or
timeout. So we will be learning how to
do pageionation on a later episode. It's
actually very easy to do for with
larable. But for now, I'm going to
return all the users
in this case. So I can get rid of this
actually as well. So let's save it.
Let's go back and test this API as well.
Uh I'll copy it.
Let me save this patch as well. So, let
me save it.
Okay, I'm going to rename it to update
user.
Now, we have get all users and the URL
is going to be API
users. We don't need to pass in anything
else. So, I'm just going to go ahead and
click send. And as you guys can see, we
are now getting all the users in our
database. So I have 13 users. This is
the last user we created. So you can see
all of them here, right?
Okay. Last but not least, we are going
to have delete user.
You probably can guess how it's going to
be. I'm going to copy our get user as
the base. So for delete, the general
convention again guys is going to be a
delete HTTP request and the URL
convention is similar to a get user. So
they all start with this users plural
and then followed with the specific user
we want to update. So this one is going
to be delete.
Of course, we're not going to be able to
return the user. We're trying to delete
it.
So to delete our user or our model we
can just say user delete. So this should
delete it. Now for the response the
general consensus we can go ahead and
just do something like response because
we don't have anything to return. So and
laral has a quick helper for us. We can
just say no content. All right because
again we don't have anything to return.
So, we're going to go ahead save this
and we can now go ahead and test it out
on Postman.
So, I'll quickly save this as well in
our collection.
And I'm going to copy this get user.
So, we need to change this uh request
type from get to delete.
And I'm going to delete the user we just
created. So I'm going to hit send
and as you guys can see
uh we are getting a 204 no content
status code. So this 204 is
automatically handled by Laravel because
we said no content right. So it's
handling the status codes for us. Now of
course to verify the user was deleted
I'm going to go back to this get request
and try again with user 13.
And as you guys can see now it is
returning a 404 not found right and even
if you go to get all
if I scroll all the way down it ends at
12 right so that user did indeed get
deleted right so okay guys so that's it
that's the process for creating CRUD
APIs in Ludal it's very easy of course
there's a lot more to do we have things
like validation authorization
uh pageionation a lot more stuff to
cover But this is the basics of it,
right? And again, things for like
validation, and pageionation, these are
things you probably are using if you're
working with Laravel on day-to-day
basis. So, it should be very easy for
you to also add them to your APIs. One
last thing I want to cover before I end
today's episode is what I showed you
guys so far. We have been using kind of
the primary key or the ID for the update
uh get and delete operations, right? So
what if you do not want to use the ID
right? So for example here if I go to
this get user what if you want to use
the email right so let me take this Dr.
forest. So I'm going to copy the email.
So what if you want to get this user
using their email instead of the ID,
right? So right now if I put the email
and click send, we get a 404 not found.
This is actually very easy to do. You
can actually tell a lot of what key or
what property or what field to use to
fetch the user. So we can just do a
double colon and then put in the field
name. So in this case, email. So Larival
will go ahead and
search the email to find that user,
right?
Same thing again, you can do it for
delete as well. So I'm going to put
email here as well. And we can put email
here as well. So let's go ahead and
quickly test it. If I go back to our API
again, try again.
Uh we are not getting a user. Let me see
why.
So everything looks correct. Uh
ah I forgot to copy the O my bad. Sorry
guys. Sometimes it happens on the video.
All right. Hopefully now it will work.
Okay. So as you can see now we are
fetching the request or fetching the
resource using the email property. Of
course the same will work for uh delete
as well. So if I come here and I instead
of this 13 I put the email and I hit
send
as you can see obviously the deletion
was successful and if I go back and I
try to fetch Dr. for us again we get F44
not found and if I go to all users and I
try again uh we no longer have that
property right so that's it guys this is
also like a quick thing I wanted to
cover on today's episode I hope you
learned something new if you have any
questions leave them in the comment
section below forget as always like the
video subscribe if you still haven't and
I see you on the next episode have a
great day bye
