Looking to hire Laravel developers? Try LaraJobs

rscapihandler-laravel maintained by mivu

Description
simple package for handle api in laravel
Author
Last update
2023/08/06 11:55 (dev-main)
License
Links
Downloads
14

Comments
comments powered by Disqus

rsc-api-handler-laravel

A simple package for handling errors, JSON templates, and repository patterns including Artisan commands.

instalation

composer require mivu/rscapihandler-laravel

Features

  • Create Artisan Handlers
  • Create Artisan Services
  • Create Artisan Repositories
  • JSON API Response Format
  • Model Response Format

Basic Usage

Artisan Commands

 php artisan make:repository Miftah

Output Path : App->Repositories->MiftahRepository.php AND App->Services->MiftahService.php

 php artisan make:handler Miftah

Output Path : App->Handlers->MiftahHandler.php

 php artisan make:enum Miftah

Output Path : App->Enums->MiftahEnum.php

Helpers

  • Validation Handler
    ValidationHandler::check([
            'page' => 'required|numeric',
            'limit' => 'required|numeric',
        ]);
  • Response Handler If you have implemented a service and repository, you can create an inside function for response handling.
    public function limit(int $limit, $filter)
    {
        $res = $this->repository->limit($limit, $filter);
        return ResponseHandlers::tryCatch($res, 'miftahs', true);
    }
  • Api Response Handlers Alternatively, you can create an API response and the output will be automatically in JSON format.
    public function find($id)
    {
        try {
            return $this->repository->find($id);
        } catch (\Exception $e) {
            ApiHandlers::exception($e);
        }
    }

Here's an example of the output: output