jenky / laravel-api by Milano

Laravel API
931
2
2
Package Data
Maintainer Username: Milano
Maintainer Contact: contact@lynh.me (Linh Tran)
Package Create Date: 2016-11-24
Package Last Update: 2021-02-20
Language: PHP
License: MIT
Last Refreshed: 2024-04-15 03:04:17
Package Statistics
Total Downloads: 931
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 2
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel API

Installation

Require this package with composer:

composer require jenky/laravel-api

Copy the package config to your local config with the publish command:

php artisan vendor:publish

or

php artisan vendor:publish --provider="Jenky\LaravelAPI\ApiServiceProvider"

Usage

Important

Please remove the api prefix in the mapApiRoutes method from App\Provivers\RouteServiceProvider.

/**
 * Define the "api" routes for the application.
 *
 * These routes are typically stateless.
 *
 * @return void
 */
protected function mapApiRoutes()
{
    Route::middleware('api')
         // ->prefix('api') Remove or comment this line.
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));
}

Create routes

Route::api($version, array $options, $callback)

The $options parameter can be omitted from the method.

Route::api('v1', [
    'as' => 'api.v1.',
    'namespace' => 'API\v1',
], function () {
    // Your routes go here.
});

Response helpers