ahmeti/response-service

Laravel Response Service

1.0.0 2018-01-12 20:46 UTC

This package is auto-updated.

Last update: 2024-10-27 01:06:52 UTC


README

Composer Install

composer require "ahmeti/response-service:@dev"

Example 01. Simple of use in Controller

<?php

namespace App\Http\Controllers;

use Ahmeti\ResponseService\Facades\ResponseService;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    public function index()
    {
        return ResponseService::status(true)
            ->message('Hi Dear!')
            ->send();
    }
}

RESULT :

{
  "status": true,
  "message": "Hi Dear!",
  "data": [],
  "status_code": null
}

Example 02. Advanced of use in Controller

<?php

namespace App\Http\Controllers;

use Ahmeti\ResponseService\Facades\ResponseService;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    public function index()
    {
        return ResponseService::status(true)
            ->message('Hi Dear!')
            ->data(['key1'=>'value1', 'key2'=>'value2'])
            ->statusCode('CODE100')
            ->responseCode(200)
            ->send();
    }
}

RESULT :

Response Headers
status: 200
{
  "status": true,
  "message": "Hi Dear!",
  "data": {
    "key1": "value1",
    "key2": "value2"
  },
  "status_code": "CODE100"
}