PHPackages                             kevupton/laravel-swagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kevupton/laravel-swagger

ActiveExtension[Database &amp; ORM](/categories/database)

kevupton/laravel-swagger
========================

Laravel Swagger generator for the Model

v1.4.2(8y ago)1813.9k5[1 issues](https://github.com/kevupton/laravel-swagger/issues)1MITPHPPHP &gt;=5.3

Since Apr 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/kevupton/laravel-swagger)[ Packagist](https://packagist.org/packages/kevupton/laravel-swagger)[ RSS](/packages/kevupton-laravel-swagger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (15)Used By (1)

laravel-swagger [![kevupton/laravel-swagger](https://camo.githubusercontent.com/0bf55fb667d4163dc96d2cb0ed17eb1f5666da9ff1e7bc3374536c2dea1b8eb8/68747470733a2f2f7472617669732d63692e6f72672f6b65767570746f6e2f6c61726176656c2d737761676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kevupton/laravel-swagger)
===================================================================================================================================================================================================================================================================================================================================

[](#laravel-swagger-)

Swagger Annotations Generator for Laravel 5.0 and up.

Introduction
------------

[](#introduction)

This package uses the Swagger PHP library and Laravel to generate an OpenAPI 3.0-compliant JSON Specification.

This package supports Laravel 5.0 and above.

Installation
------------

[](#installation)

```
$ composer require kevupton/laravel-swagger
```

Table Of Contents
=================

[](#table-of-contents)

> - [Models](#models)
> - [Controllers](#controllers)
> - [Custom Handlers](#custom-handlers)
> - [Overriding Values](#overriding-values)
> - [Seperate Container Class](#seperate-container-class)

Models
------

[](#models)

### Usage

[](#usage)

> `\Kevupton\LaravelSwagger\scan($path, $models);`

Define your Eloquent Models as shown below, in order for `laravel-swagger` to include in your specification:

```
/** @var Swagger\Annotations\Swagger $swagger */
$swagger = \Kevupton\LaravelSwagger\scan(app_path('location'), [
    'models' => [
        /** All models go in here */
        \App\Models\User::class,
    ]
]);
```

Example model:

```
class User {
  protected $table = 'users';
  protected $fillable = ['first_name', 'last_name', 'image_id'];
  protected $hidden = ['created_at', 'updated_at', 'image_id'];
  protected $with = ['image'];
  public $timestamps = true;

  public function image() {
    return $this->belongsTo(Image::class);
  }
}
```

### Output

[](#output)

```
"App\\Models\\User": {
    "properties": {
        "id": {
            "type": "string"
        },
        "first_name": {
            "type": "string"
        },
        "last_name": {
            "type": "string"
        },
        "image": {
            "$ref": "#/definitions/App\\Models\\Image"
        }
    }
}
```

Controllers
-----------

[](#controllers)

Laravel-Swagger allows you to define a generic, customized output for each Controller. It requires a parent controller to define the base of each output response.

### Getting Started

[](#getting-started)

For example, you have controllers `TestController`, `FooController` and `BarController` which serves API requests.

Each of the `index` methods share similar functionality, which is to display a list of results with pagination. The router definition is as follows:

### Example Router Definition

[](#example-router-definition)

```
Route::get('/v1/test', ['uses' => 'TestController@index', 'as' => 'v1.test.index']);
Route::get('/v1/foo', ['uses' => 'FooController@index', 'as' => 'v1.foo.index']);
Route::get('/v1/bar', ['uses' => 'BarController@index', 'as' => 'v1.bar.index']);

Route::get('/v1/bar/{bar}', ['uses' => 'BarController@show', 'as' => 'v1.bar.show']);
```

---

*I have a custom package to help with Controller functionality which can be found at [Ethereal](http://github.com/kevupton/ethereal)'s [Resource Trait](https://github.com/kevupton/ethereal/wiki/resourcetrait)*

---

Since these Controllers share the same basic output, you can utilize a `BaseController` that the above Controllers may inherit from. An example `BaseController` is shown below:

### Example Base Controller

[](#example-base-controller)

```
