devianl2/tenant-support

Microservice support package

1.0.13 2022-06-01 08:50 UTC

This package is auto-updated.

Last update: 2024-04-29 04:59:52 UTC


README

Tenant support is a laravel package that simplify and focuses on business function development.

For each microservice development, you need to follow instruction below to ensure the application is standardize.

Step 1:

Install from composer

composer require devianl2/tenant-support

Run the following command for to export error view template

php artisan vendor:publish --provider="Tenant\Auth\TenantSupportProvider"

Go to App/Provider/RouteServiceProvider.php and modify rate limit to 600

protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(600)->by(optional($request->user())->id ?: $request->ip());
        });
    }

Step 2:

Go to laravel project / app / Exceptions / Handler.php and modify from

class Handler extends ExceptionHandler {
protected $dontReport = [
        //
    ];
    ....
}

to

class Handler extends ExHandler {
// remove all other functions and variables (Exhandler already included all that exceptions)
protected $dontReport = [
        //
    ];
}

Step 3:

All controllers that required API return, use the traits ApiResponse.php. E.g:

import Tenant\Support\Traits\ApiResponse
class UserController extends Controller {
    use ApiResponse;
}

##functions

public function successResponse($data, $statusCode = Response::HTTP_OK)
    {
        return response($data, $statusCode)->header('Content-Type', 'application/json');
    }
    public function errorResponse($errorMessage, $statusCode)
    {
        return response()->json(['error' => $errorMessage, 'error_code' => $statusCode], $statusCode);
    }
    public function errorMessage($errorMessage, $statusCode)
    {
        return response($errorMessage, $statusCode)->header('Content-Type', 'application/json');
    }

Step 4:

All repositories that required paginate, use the traits EloquentPaginate.php. E.g:

import Tenant\Support\Traits\EloquentPaginate
class UserModel extends Model {
    use EloquentPaginate;
}

Sample to use the EloquentPaginate:

$templates  =   QuestionTemplate::with([
            'sections'
        ]);

        if (array_key_exists('search', $query) && !empty($query['search']))
        {
            $templates =   $templates->where('title', 'LIKE', '%' . $query['search'] .'%');
        }

        return $this->execute($templates, $paginate, $limit);

##params_

  1. Query builder is referring eloquent query
  2. $paginate is true/false
  3. $limit is int (Minimum 1)