DEV Community

Mesak
Mesak

Posted on

Laravel package api-response

I mentioned a method before, which is to use the unified processing of the controller return value to output the API response. For this reason, I wrote my method into a package to make it more convenient to use.

package in :
https://github.com/mesak/laravel-api-response

in Laravel 8 or 9

use command :

composer require mesak/laravel-api-response
Enter fullscreen mode Exit fullscreen mode

your can install this package

then use two step

change Controller and change Exception\Handler

Exception\Handler

change your app/Exceptions/Handler.php file to extend Mesak\LaravelApiResponse\Exceptions\Handler

namespace App\Exceptions;

use Mesak\LaravelApiResponse\Exceptions\Handler  as ExceptionHandler;

Enter fullscreen mode Exit fullscreen mode

Controller

change your api controller, to extend Mesak\LaravelApiResponse\Http\Controllers\Controller

namespace App\Http\Controllers;

use Mesak\LaravelApiResponse\Http\Controllers\ApiController as BaseController;

class MainController extends BaseController
{

}
Enter fullscreen mode Exit fullscreen mode

then enjoy this

Top comments (0)