Generally, we are using a Swagger in Laravel. it will take time if we set up swagger manually. so, In this article, I going to show you very easy steps for setup in Laravel.
You can watch the following video tutorial as well.
Steps 1:
You should download these assets from here. unzip the folder and go to the public directory. you can found the swagger directory in the side public folder. let open the swagger directory and you can see the following files.
- jquery-2.1.4.min.js
- style.css
- swagger-bundle.js
- swagger.yaml
If are you still confuse then visit this link for files.
now, Copy the swagger directory and put it in your laravel application on the same path.
Steps 2:
We need to load swagger with proper swagger UI. so, let navigate to resources/views on the downloaded source code project.
You can see the swagger directory inside the views directory. copy the swagger directory to your laravel application on the same path. I don’t think you need to do anything in this view file. let’s go to the next step.
Steps 3:
You need to update this swagger.yaml file. you should update the following details first. and then add APIs documentation in this file. Api document example given here. you can refer it.
info:
description: LPT APis
version: 1.0.0
title: LPT Frontend API's
basePath: /api/
Steps 4:
In this step, you need to create a route for loading swagger docs. so, let’s open the web.php file add the following few lines of code.
Route::get('/docs', function () {
return view('swagger.index');
});
Now, run a command php artisan serve and open http://127.0.0.1:8000/docs or open a virtualHostDomain/docs if you have one.
You should watch this tutorial as well if you using InfyOm Generator