PHP code example of khsing / laravel-restapi

1. Go to this page and download the library: Download khsing/laravel-restapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

khsing / laravel-restapi example snippets


Khsing\Restapi\OAuth2ServiceProvider::class,
Khsing\Restapi\RestapiServiceProvider::class,


Passport::routes(function ($router) {
    $router->forAccessTokens();
    $router->forTransientTokens();
});

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:api');

    protected $middlewareGroups = [
        ...
        'api:auth' => [
            'auth:api',
            'api.auth',
        ],
    ]

    'auth' => [
        'restapi' => \Khsing\Restapi\DingoAuthServiceProvider::class,
    ]

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['middleware' => 'api:auth'], function ($api) {
    $api->get('user', function (Request $request) {
        return $request->user();
    });
});

bash
php artisan passport:client