Once you already opened it, we'll start on Creating the product schema, it'll just have some basics data like : Ĭreate the product table migration with this command :Ĭommand above will create you a migration file which will be located on database/migrations, locate the create_products_table file and open it up. One more step is done, the next step is to create the database migration or defining the database schema, while working with laravel, you could easily utilize the artisan's make:model with -m option to automatically generate a model and a migration, unfortunately this is not available in Lumen, therefore we'd have to create the migration first and later on, create the Model. env file configuration as shown above is to make sure you filled your Database Configuration correctly, configuration related to Database are those started with **DB_**. env file, and do the configuration for your project database (don't forget to stop the server running first) Once your project folder are loaded, open the.
Once you're done with the database, now open your favorite Code Editor and open your project folder. If you are using linux, start the mysql / mariadb service via your terminalĬreating The Database Via Terminal / CMD :
* Note : if you are using Windows and XAMPP, dont forget to turn on the MySQL Service and Apache (if you are going to use PHPMyAdmin) via the XAMPP Control Panel. We need a database to later save / hold the migrated table from lumen, therefore we'll need to create one in MySQL, i'll give the database name "product-rest", and i'll do it via the terminal to speed up the process, you can also create it via PHPMyAdmin.
If you get the same response as shown on image above, it means that the project has built sucessfully and you're ready to move on to the next step. You can test the endpoint via Postman or Your web browser by sending a GET request to the "/" route Once the project has successfuly built, you can change your directory to the project directory (product-rest-api) and run this command to start the server : įirstly, we'll have to create the project first, by executing this command : In this tutorial, we'll create a simple CRUD for a Product Entity, we'll name our project "product-rest-api", please kindly remember that by the time this tutorial is being written, the latest release of Lumen and Laravel is 8.0. SQL Knowledge (would be really helpful).Several things you need to know before following this post :
PHPMyAdmin ( You get this automatically via XAMPP, you can install it on linux via Packet Manager also).MySQL Server ( You can install it via XAMPP on Windows, or via your favorite Packet Manager on UN*X like system).When you are only intended to Create an API, you wont need lots of Laravel default Libraries / Dependencies, because the goals is only to output a plain data formatted with most probably JSON, therefore we'll use Lumen, a micro-framework which utilize laravel's best part, with smaller size and faster execution time too! What should i know or have to follow this post?
Hello there ! I am Rep, Software Engineer in the making and currently a 3rd year Computer Engineering student ! In this post i am going to share a quick guide on creating a CRUD ( Create, Read, Update, Delete ) Rest API With Lumen, MySQL Database and also Eloquent ORM.