PHP code example of sdv / laravel-endpoint

1. Go to this page and download the library: Download sdv/laravel-endpoint 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/ */

    

sdv / laravel-endpoint example snippets


// config/app.php
'providers' => [
    ...
    SdV\Endpoint\EndpointServiceProvider::class,
]
app/Exceptions/Handler.php

// routes/api.php
Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1'], function () {
    Route::resource('posts', 'PostController', ['except' => [
        'create', 'edit'
    ]]);
});

php artisan endpoint:make:model Post
app/Post.php

php artisan endpoint:make:controller Post v1
app/Http/Controllers/Api/V1/PostController.php

php artisan endpoint:make:repository Post
app/Repositories/PostRepository.php

php artisan endpoint:make:transformer Post
app/Transformers/PostTransformer.php

/api/v1/topics?page=2

/api/v1/topics?per_page=50

/api/v1/topics?limit=all

/api/v1/topics?sort=name

/api/v1/topics?
$this->forbidden('Access forbidden.')
$this->unprocessableEntity('Invalid fields.')
$this->serverError('Internal server error.')