1. Go to this page and download the library: Download abdphyr/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/ */
namespace App\Http\Requests;
use Abdphyr\Swagger\Attributes\DTO\FileParam;
use Abdphyr\Swagger\Attributes\DTO\RequestParam;
use Illuminate\Http\UploadedFile;
#[RequestParam(key: 'name', value: 'Rich dad and poor dad')]
#[RequestParam(key: 'year', value: '1997')]
#[RequestParam(key: 'series', value: 'DWAR')]
#[FileParam(key: 'file', value: new UploadedFile('path/to/file'))]
class BookUpsertRequest extends BaseRequest
{
public function rules(): array
{
return [
'name' => ['
namespace App\Http\Controllers;
use Abdphyr\Swagger\Attributes\Http\ActionMethod;
use Abdphyr\Swagger\Attributes\Http\ActionController;
use App\Services\BookService;
// Absolute path: http://localhost:8000/api/book
// This controller API data visible `default` page
#[ActionController(uri: 'book', pages: ['defaut'])]
class BookController extends Controller
{
public function __construct(protected BookService $service) {}
// Path: http://localhost:8000/api/book?name=Rich...
// "auth: false" means this endpoint don't h: http://localhost:8000/api/book
#[ActionMethod(uri: '', method: 'POST', summary: 'Creating Book')]
public function store(BookUpsertRequest $request)
{
return $this->service->create($request->validated());
}
// Path: http://localhost:8000/api/book-top-all
// Absolute path is not used beacuse of `uri` starting with `/` that marks this `uri` is `ABSOLUTE PATH`
#[ActionMethod(uri: '/book-top-all', method: 'GET', , summary: 'Top books')]
public function topBooks()
{
return $this->service->topBooks();
}
}