---
title: 'Build a RESTFUL API with Laravel'
source: 'https://youtube.com/watch?v=dbpvrOsp48Y'
video_id: 'dbpvrOsp48Y'
date: 2026-07-28
duration_sec: 1183
---

# Build a RESTFUL API with Laravel

> Source: [Build a RESTFUL API with Laravel](https://youtube.com/watch?v=dbpvrOsp48Y)

## Summary

This tutorial demonstrates how to build a RESTful API using Laravel, covering CRUD operations for an anime list. The video walks through setting up a Laravel project, creating a model with migration, defining API routes, and testing endpoints with Postman.

### Key Points

- **Prerequisites** [00:00] — Requires MySQL and Postman. The presenter uses MAMP to run MySQL locally.
- **Create Laravel Project** [02:25] — Use Composer to create a new Laravel project named 'laravel-api-youtube'.
- **Generate Model and Migration** [02:54] — Run 'php artisan make:model Anime -m' to create the Anime model and its migration file.
- **Configure Database** [04:05] — Create a database in phpMyAdmin named 'laravel_api_youtube' and update the .env file with database credentials.
- **Define API Routes** [05:25] — In routes/api.php, define GET, POST, PUT, and DELETE routes for the Anime resource.
- **Run Migrations** [07:55] — Run 'php artisan migrate' to create the animes table. Update migration to include 'title' (string) and 'watched' (boolean) columns.
- **Set Fillable Fields** [09:15] — Add protected $fillable = ['title', 'watched']; to the Anime model to allow mass assignment.
- **Create Anime (POST)** [10:00] — Define POST route to validate and create a new anime using Anime::create().
- **Update Anime (PUT)** [12:57] — Define PUT route with route model binding to update an anime by ID.
- **Delete Anime (DELETE)** [16:50] — Define DELETE route to delete an anime by ID using $anime->delete().

### Conclusion

The video successfully demonstrates building a basic RESTful API with Laravel, covering all CRUD operations. It's a solid foundation for beginners to understand API development in Laravel.

## Transcript

what is going on fellow developers my
name is telepot and in today's
video we're going to be creating a
laravel api
now you're going to need some
pre-requisites for this before getting
started
and the pre-requisites you
need is mysql and postman
now as you can see here this is postman
it allows you to make api requests or
restful a
restful request to an api
like this as you can see here we can do
a get animate one and as you can see
there
we get the i d the title and
if it's been watched or not um again you
can create a new anime we can put one up
and we can delete one from this api
so this is what postman could do but
you're also going to need some sort of
mysql database you can connect to
i'm actually cheating the system and
using mamp so mamp allows you to run
php applications using apache it also
installs mysql and when you start it
will start in mysql
server where you can access at localhost
um if you go into your settings here and
you go ports you can see your mysql port
here you can change it or set to
whatever you
think you need but as you can see that's
how you um
can set up using mamp um i'm not going
to show you how to download them simply
just google them and
find it there or check out one of my
other videos either getting started with
laravel or
my learn how to use php so without
further ado
let's get on with the video
today's video is brought to you by
cloudways a managed cloud hosting
platform for your php based applications
cloudways offers peace of mind and
flexibility to let you focus on growing
your business and reach new milestones
now with cloud wage
you get an optimized stack manage surf
and application
backups staging websites integrated
getting composer
and the choice of five cloud providers
like aws digitalocean
lynode and more so if you're an agency
or an e-commerce business and looking
for a managed solution
then go for cloudways without wasting a
moment
you can use the promo code tylerp
when signing up via the link in the
description to get 15
free hosting credit and by the way i
really like their slogan
moving dreams forward
so the first thing we're going to need
to do is create a new
rfl project um so to do that we're going
to use composer
we're going to create a project and
we're going to call it well we're going
to
we need to use larafell and then we need
to give it a name so this one is going
to be
larafell hyphen api hyphen youtube i'm
going to hit
enter and that's going to create our
project so our project's now
completed already so to get started what
we're going to do
is we're going to run php
artisan make model
and then we're going to give the model a
name now we're gonna be creating an
anime
uh list like what my anime list what i
wanna watch sort of thing
api so we're gonna call this make model
anime um
and then we're gonna also do a hyphen
and i'm gonna say
uh we're to make a migrations and we're
going to make
the well it's just in migration so what
we're going to do is phps and make model
anime and the migrations which go with
this
we can actually do migrations i believe
um so let's hit enter could not find
file oh
sorry we need to actually cd into the
directory so let's cd
into the laravel api youtube
and then let's run that command again uh
just to let you know i made a mistake it
wasn't migrations it's migration
um and now that has done it's also
created our migration table
there so let's open this up with vs code
or whichever
text editor you prefer to use i'm going
to open this up
and let's close that uh
let's zoom out one just for now um we'll
zoom back in when we're done
and the first thing we want to do is go
into dot emp and we need to update our
database so we actually need to go and
create a database
so what we need to do is open up our
browser
if i can open it there we go and then we
want to go to
localhost forward slash php
my admin and that's if you're using mamp
if you're using saying else obviously go
to where for you stored your database
we want to create a new item here and
we're going to call this larafell
underscore api underscore youtube hit
create
and it will create us a new database so
now we need to take this name
go back into our dot emv file
and go larafell underscore api
underscore youtube and also the password
is root for map
um and it's root for map but also use
whatever database password and username
your
my sql setup uses so let's close the dot
emp file and actually head
into the app and models now actually if
we open this up
we have class anime extends model here
now we're going to have to make a couple
of changes to this i'm not going to do
them now because i want to show you the
errors that happen if you don't make the
changes here
um so let's actually go into our routes
uh our api.php and we're now going to
set up our first
route so what we need to do is go
route route get because we're going to
be making a get request and we're going
to get
from forward slash anime we're then
going to run a function
and inside this function we're just
going to return anime
all and what this is going to do it's
going to go to our anime model it's
going to know what
how to connect to it to the mysql it's
going to run a query
to get all of our anime items
inside of that array and it's going to
return it so what we need to do
is actually use um
app forward slash models
backlash anime also a lot of people
mentioned that that's just the incorrect
path because it's
it's a capital a where it's in the
perfect lower case when you
use something you need to capitalize the
first layer because if you don't it will
not find that model so let's save that
and now if we go and run this inside of
postman so if we bring postman
up here let's create a new
collection we're going to call this
anime list
youtube let's create let's click in here
and click add a new request we're going
to call this get
anime save and also
let's actually close all of these
there we go so let's open this one now
we need to actually surf this file here
so we need to press control option t
to open up our terminal and i'm going to
run php artisan
surf to run our um
our app says run there you go so now we
can see the link here
so let's copy that go back to postman
paste it in here
but now every so we did four slash anime
but
every single route will be prefixed with
forward slash api forward slash route
so we always need the api when we're
using this
and now if we hit send we can see
we're getting an error base table or few
not found
laravel underscore api underscore
youtube dot
animes and you're thinking to us but we
created anime
well there's actually two things we need
to do before this actually gonna work
so we need to go back to our app here
and we need to run
let's close this we need to run php
artisan migrate which will create our
anime table
so if we go to the
database migrations and click on the
anime table you can see what does
it creates a new animaze table
so what we need to do is go in here and
do
table we need to create a string
and in here we need to call this
uh title we don't need another table
which will have a boolean sorry not
create a new table use table and we'll
create a new boolean called watched
and hit save and now that way this is
going to be our structure for our
anime database so we actually need to
um create a so what we need to do is php
artisan migrate
rollback now what this will do is roll
back all the changes we made
and now because we've updated our
um our migration we can now run php
artisan migrate again
and this time it's going to create our
animes table but with the correct
structure let's close this
and let's go into our anime here and we
want to create a protected
sorry a protected table
and set this equal to the table name
which is going to be animes
let's open up our timeline again and
clear that and now run
php artisan surf
let that surf it let's go back
to our api and or to our postman and
let's send that request again
and there you go we get an empty array
so that's cool obviously notes come back
so we can't really tell if that's worked
or not
but we we aren't getting any errors so
the next step is actually to create a
new anime
so to do that let's create a new request
let's
copy this link here put this in here
anime and let's change this to a post
now what the post request will do will
allow us to
actually create a new anime so let's set
that route inside of our
um laravel application so i do say root
post to forward slash anime
i'm then going to run the function
and inside of this function we're going
to basically
check the request and what we're going
to do is we're going to say
just to record can we validate the
request
and the items we want to validate is the
title we want to make sure
we definitely have a title when we
create
an anime post we're then going to return
anime create
and then we're going to pass through a
title which is going to be our request
title and then we're going to pass
through watched
which will be our request oh
our request watched so what this means
is we're going to check if we're making
a request
so when we check the request we're going
to validate it to make sure
we definitely have a title if we don't
have a title
that means it's going to throw back an
error saying hey
you need a title then what we're going
to do is we're going to return
we're going to create a new anime we're
going to call title
request title watched request
watched so basically we're just getting
the title from our body
our json and the request from our json
so let's go back to postman quickly
and let's actually try and do this let's
go to our body
let's click raw and let's put in some
jason
now let's just pull us through a title
and call it
uh tokyo ghoul
and have we watched it let's say no so
we'll go pass through false
so let's try and send this request i'm
going to warn you this will throw an
error as you can see we are getting an
error now
it basically is not allowing us
to it's basically a security layer from
um
laravel to fix this we need to go into
our model
and now we need to create another
protected variable called
fillable and we've got to set this to an
array and
inside this array we need to give what
we're allowed to fill mass
fill which will be title and watched
there you go so now if we go back to
postman and try to run this again click
send
you can see it's now created so if we go
back to our get anime request
and send that request you can see we get
returned
a object with our tokyo ghoul anime
added
so let's now save this one and call this
one
create anime save to the list and there
you go we've got them saved in our
little list over here which is useful
so the next request we need to make is
actually updated let's say we've
actually watched tokyo ghoul
so let's now go back let's go into our
api
and let's create a new route call it
uh put for this route because we're
gonna be updating so we're gonna say
anime forward slash and now this one is
gonna look a bit different we're gonna
use brackets
and pass through the anime and this is
actually just going to be the id
but we need to give it the name of anime
or whatever matches
our um model here
so in here let's now type in function
anime dollar anime
and down here what we want to do is say
return dollar anime
update with the array
of title so we're gonna pass by qatar
which is request
title and our watched
which will be request
watched so there you go
now we actually only want to update our
watched element
but we can also update our title too but
let's remove this and just update our
watch element for now
so just to explain this so what we're
doing is we're making a put request
to anime forward slash anime which is
actually going to be the id so this
would be such as one
two three so let's just pipe in anime
here
and then we're going to take this name
and we're going to create a variable
outfit over on the right side which is
going to be
a model so what this is actually doing
to create this laravel is running
anime or sorry anime
find by id
and it's going to take an id and it's
basically returning it that way
so what's it basically it's just trying
to find an id
find an anime with the anime model with
the id
of whatever we pass through here and
it's now returning it into
a actual object we can use to update
so let's now go and test this inside of
postman so let's create a new request
let's just copy the route here let's
put it into a put and now let's pass
through an id so if we go back to get
anime you can see the id of tokyo goal
is one
so let's go in here and just paste in
the one
let's go and create a body of raw
type jason and let's just say watched
which is going to be set to troops we've
now watched it let's say it's sent
and you can see we get a one now one
means it has worked if we go back to get
anime and we resend this request
you can see watch is now returning with
one as well so one just means true
and that's what they're saying it's
basically saying success is equal to
true
and that is now the um update
anime root done now if we want to we can
go back here and we can also pass
through
a title and we could say request
title save that and go back
now if we make this request again you
can see we're going to get an error
because
title cannot be null so what we need to
do is in here
say title and pass through the title of
the anime
hit save click send and that comes back
with one again so if we go to get anime
refresh you can see it's just there so
let's just actually make a change let's
say tokyo ghoul
updated or we could say re send
re is one of the update or one of the
anime seasons
and there you go tokyo ghoul re we've
added it to a watch list
let's save that and there you go that is
now done now there's one last route we
have not covered and that is deleting an
anime so let's create a new one quickly
let's create one let's say
naruto watched true already so let's
create that
as you can see it's come through as true
so if we go to our get animate and we
sent
you see we get two items now we've got
one which toggle and naruto
let's say we we actually didn't want
tokyo ghoul in there at all
um we could now delete it so let's go
back here
let's go to our route let's create a
delete
and we're gonna say forward slash anime
forward slash
the same route as before so we're gonna
do the anime
we're gonna do function again
anime dollar anime
and now to delete this we're gonna
return i'm gonna say
anime delete
and it's as simple as that to set up a
delete request you just get the object
by using the id pass through the url
and then we delete it using this
function here so
save this let's go back let's create a
new
let's copy the route again
let's not let's do a delete
body we don't actually need a body for
this this time so we can actually just
run this
click send and as you can see it's
successful so it's come back as one
so if we save this as uh delete
anime save let's go to get anime and see
if tokyo ghoul is still there so let's
hit sent
and as you can see it's been taken away
it's been deleted now we just have
naruto and that is as simple as it is to
make an
apa and a an api
in laravel it's super basic super simple
and it works really well now in the next
video we're going to look
at actually creating some sort of
website or some sort of laravel a bigger
laravel project
um but for now i hope you've enjoyed
this video if you have don't forget to
leave a thumbs up
smash that subscribe button share it
with all your friends leave any comments
or feedback if you get stuck at any
point or you have any questions don't
forget to just drop it in the comments
below
and just as a quick shout out don't
forget to check out my twitter it's
in the description below and same with
my new discord surfer where
you can join us get involved with the
community and
if you need any help or anything like
that i will be there to try and help you
but anyway guys thank you for watching
this video i will see you in the next
one
peace out
[Music]
you
