PHP code example of laxity7 / laravel-swagger

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

    

laxity7 / laravel-swagger example snippets


use Laxity7\LaravelSwagger\Generator;

$generator = new Generator();
$generator->generate();

'parameterParsers' => [
    \Laxity7\LaravelSwagger\Parsers\Requests\Parameters\PathParameterParser::class,
    \Laxity7\LaravelSwagger\Parsers\Requests\Parameters\QueryParameterParser::class,
    \App\Swagger\CustomBodyParameterGenerator::class,
],

Route::get('/api/user/{id}', ['UserController', 'show']);
Route::get(
    '/api/user/{id}/check',
    /** 
    * Check user exist
    * @param int $id User ID 
    */ 
    fn(int $id) => User::where('id', $id)->exists();
);

use Laxity7\LaravelSwagger\Attributes\Request;

class UserController extends Controller
{
    /**
    *  Return all the details of a user
    *
    * Returns the user's first name, last name and address
    * Please see the documentation [here](https://example.com/users) for more information
    *
    * @deprecated
    * 
    * @param int $id User ID
    */
    public function show(UserShowRequest $request, int $id)
    {
        return User::find($id);
    }
    
    /**
    * @request UserShowRequest
    */
    public function show(int $id)
    {
        $showRelationships = request()->get('show_relationships')
        return User::find($id);
    }

    #[Request(UserShowRequest::class)]
    public function show(int $id)
    {
        $showRelationships = request()->get('show_relationships')
        return User::find($id);
    }

    /**
    * @ignore
    */
    public function notShow(int $id)
    {
        return User::find($id);
    }
}

use Illuminate\Foundation\Http\FormRequest;
/**
 * @property array $fields List of user fields
 */
class UserShowRequest extends FormRequest
{
    /** Is it necessary to show the relationship? */
    public $show_relationships;
    
    public function rules(): array
    {
        return [
            'fields' => 'array'
            'show_relationships' => 'boolean|