DEV Community

Mesak
Mesak

Posted on

1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay