Skip to content

Latest commit

 

History

History
121 lines (89 loc) · 3.02 KB

README.md

File metadata and controls

121 lines (89 loc) · 3.02 KB

Laravel Intuition

Latest Version on Packagist Laravel 8.x Total Downloads License

This package is for building the same format APIs responses in Laravel.

Table of Contents

Installation

You can install this package via composer using this command:

composer require fawkescreatives/laravel-intuition

The package will automatically register itself.

/*
 * Package Service Providers...
 */

LaravelIntuition\LaravelIntuitionServiceProvider::class,

Configuration

php artisan vendor:publish --provider="LaravelIntuition\LaravelIntuitionServiceProvider"

You can change the response by modifying the boolean values in config/intuition.php.

You can customize the http status code class and default response values as needed.

eg..,

. intuition.php

return [
    'status'               => true, // boolean
    'success'              => false, // boolean
    'message'              => false, // boolean
    
    // default response values
    'data_key_default_type'  => null, // null || array() // data key ရဲ့ default value type အတွက်
    'http_status_code_class' => LaravelIntuition\Http\HttpStatusCode::class,
    'default_success_status' => [
        'status'     => LaravelIntuition\Http\HttpStatusCode::SUCCESS,
        'status_ref' => LaravelIntuition\Http\HttpStatusCode::SUCCESS_REF
    ],
    'default_error_status'   => [
        'status'     => LaravelIntuition\Http\HttpStatusCode::BAD_REQUEST,
        'status_ref' => LaravelIntuition\Http\HttpStatusCode::BAD_REQUEST_REF
    ]
];

. output
{
    "status": 200,
    "status_ref": "Ok"
    "data": null
}

It is recommended to use App\Http\HttpStatusCode for https status code.

namespace App\Http;


class HttpStatusCode
{
     /**
     * Information code
     */

    const CONTINUE = 100;
    const EARLY_HITS = 103;

     /**
     * Success code
     */

    const SUCCESS = 200;
    const CREATED = 201;
    const ACCEPTED = 202;

    /**
     * Client error code
     */

    const BAD_REQUEST = 400;
    const UNAUTHORIZED = 401;
    const NOT_FOUND = 404;
}

Testing

You can run the tests with:

composer test

License

The MIT License (MIT). Please see License File for more information.