Laravel Movies Api Tutorial

Laravel Movies Api Tutorial

In this comprehensive tutorial video, you’ll learn how to create a Laravel Movies API with a MySQL database. The video will take you step-by-step through the process of building an API that can be used to fetch, add, update and delete movies from a MySQL database using Laravel, a powerful PHP web application framework.

 

 

Starting from scratch, you’ll be guided through the setup and installation of the necessary software and tools, including Laravel and MySQL. You’ll then learn how to create a movies table in your MySQL database and define the appropriate endpoints in your Laravel application to interact with the data.

Throughout the video, you’ll be shown best practices for writing clean, maintainable and scalable code, as well as tips and tricks for troubleshooting common errors that may arise. By the end of this tutorial, you’ll have a fully functioning Laravel Movies API that you can use in your own projects, and a solid understanding of how to work with MySQL databases in Laravel.

if you have any question about Laravel Movies Api Tutorial, feel free to message me.

download code

 

Lets create a laravel Api
We will create a movie or blog api
our first step is to create a new laravel project
Here is the command

laravel new myproject_name

Lets run this command in terminal….
This process will take time and you need

internet connection also…

I will fast forward it…

As you can see , our project is created sucessfully.

Now we will open the project in vs code.

you can open it in anything.

2nd step is run the project..
our command to run project is..
php artisan serve –port=8080
I love port 8080…

sometime your antivirus(avast) will delete the server.php or other php files.
you should know that also.
my project is successfully working and running in browser…

Now we will check our database connection
.env file is used for database setting.
my database name is lara1
you can use any database.
it is totally up to you..
by default there is not password in xamp

Now I will create controller and models and migrations with the help of only one command.
php artisan make:model my_model_name –all
–all flag is very very important
As you can see, our command is successful.
we have created model and also created controller and database migrations also.
Now I want to create my table fields.
I need movies name and release year only
also movies language…..
by using this line we are creating only string fields
$table->string(‘name’);
you can create integer and double for decimal points also.
Now I have to run migrations
here is the command…
php artisan migrate
if you any error , you need to these line
//this is added by gulkhan
use Illuminate\Support\Facades\Schema;
also one more line in
//this is added by gulkhan
// Fix for MySQL < 5.7.7 and MariaDB < 10.2.2
Schema::defaultStringLength(191); //Update defaultStringLength

sometime it give error.
so this is the solution I know.
this time our command is successful..
we have create tables in database.
lets check it.
I want to add some data to this database manually
Lets do it together…
you should know be able to add data to your database…
I will add some more records in database..
we have create movies record..
Now I want to fetch all the data
Lets create roues for it.
I will create a route for api first….
I love apis guys
You can integrate it in your mobile app..
use App\Http\Controllers\MoviesController;
this line will import the controller in api folder…
Now I will share the rotue/path
Route::get(‘/’,[MoviesController::class,’index’]);
this line will create rotue for you
you can modify it like below
Route::get(‘/movies’,[MoviesController::class,’index’]);
or you can change it post
Route::get(‘/posts’,[MoviesController::class,’index’]);

it is totally up to you…
Now I will fetch data and show in json format.. for use in react or any other frontend framework…
I love to work in flutter and react…
wow , guys
we are successful to get all data…
Now what to do.
I will create a route to post data
delete data
update data…
I think delete is easy…
so I will do delete part 1st.
you also need a postman/or thunder client
for api testing…
guy lets do the update operation
what do you think if we do post method first..
lets do post method first…
now we will create a update or put method…
now we have completed post… creating new entries…
lets work on fetching one entry by id
it is very very easy…
now we will work on update api
it is preferable to use post instead of put in laravel… accroding to me..
// we have completed all the routes.
now you can practice it.

 

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: