This is the 20th day of my participation in the August Text Challenge.More challenges in August

First, link the VM to create a new project

1.1. Link VMS

sudo vagrant up:

1.2. Create a new project

Go to the code folder and run the commandComposer create-project --prefer-dist laravel/laravel=8.4.4 shopProjectApiCreate a Laravel project:

1.3. Modify the configuration

Then changehomestead.yaml:Run the commandvagrant reload --provisionRestart the VM:And then in/etc/hostWrite domain name mapping below:

Install DINGO/API

Install dingo/ API to view this blog.

Three, API login authentication configuration

API login authentication configuration check out this blog.

Four, routing,

4.1 Routing Layer

Copy the two api.php files in the routes folder and rename them auth.php and admin.php.

4.2 Route Registration

Register the two routes you just created under app\Providers\Providers\ routeserviceprovider.php:

            /** User authentication related routes */
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/auth.php'));

            /** Background routing */
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/admin.php'));
Copy the code

Five, controller preparation

5.1 Controller Groups

Create 3 folders Admin, Auth, and Web under app/Http/Controllers.

5.2 Creating a Basic Controller

Command:php artisan make:controller BaseController BaseControllerCode:


      

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Dingo\Api\Routing\Helpers;

class BaseController extends Controller
{
    use Helpers;
}
Copy the code

With dingo/ API response generators, controllers need to use dingo/ API/Routing/Helpers. Any control created later inherits from the underlying controller.

6. API documentation

We use API documentationshowdoc.We can create a new project and document the project in the sub-module, which will not be covered here.

If you find this article helpful on your way to learning PHP, please follow me to like and comment on it. Thank you, your blog is definitely another support for me to write.