How to Create a REST API with Laravel Lumen - BOOKC -->

How to Create a REST API with Laravel Lumen

Wednesday, November 6, 2019

Create a Lumen Project
=>  composer create-project --prefer-dist laravel/lumen your-project-name

Test the installation worked

=>  php -S localhost:8000 -t public

Create migration files

=>  php artisan make:migration create_players_table --create=players

Create Seeding Files

=>  php artisan make:seeder PlayersTableSeeder
=>  php artisan migrate --seed

Create Route Endpoints

$router->group([
    'prefix' => 'api/v1',
], function () use ($router){
    $router->get('/players', 'PlayersController@index');
    $router->get('/players/{id}', 'PlayersController@show');
    $router->post('/players', 'PlayersController@store');
    $router->patch('/players/{id}', 'PlayersController@update');
    $router->delete('/players/{id}', 'PlayersController@destroy');
});


Create Lumen Models

=>  $app->withEloquent();

Create a folder called Models in /app.
Create a file called Player.php in /app/Models.
Copy and paste the code below in your Player.php file.