项目作者: akilsagitarius

项目描述 :
This is a response message with code
高级语言: PHP
项目地址: git://github.com/akilsagitarius/message.git
创建时间: 2018-11-14T08:42:51Z
项目社区:https://github.com/akilsagitarius/message

开源协议:MIT License

下载


Message JSON Response And HTML Response (Commingsoon) Laravel 5

FOSSA Status

A minimal package for JSON Response API and HTML Response (Commingsoon) to clients, Laravel.

Getting Started

Install the package via composer.

Download package dengan composer

  1. composer require akilsagitarius/message

or

  1. {
  2. "require": {
  3. "akilsagitarius/message" : "dev-master"
  4. }
  5. }

Register the service provider.

This package makes use of Laravel’s auto-discovery of service providers. If you are an using earlier version of Laravel (< 5.4) you will need to manually register the service provider.

Add akilsagitarius\message\MessageServiceProvider::class to the providers array in config/app.php.

example

  1. 'providers' => [
  2. ....
  3. akilsagitarius\message\MessageServiceProvider::class,
  4. ]

Register the service provider.

Now, publish the configuration code response to your provider

  1. php artisan vendor:publish --tag=public --force

Usage

Basic

NOTE: The response code returned in the body payload will be set as the actual HTTP header response code as well.

Regular Responses

This is simple response

  1. Route::get('/message', function () {
  2. $reuslt = Message::success(200)->get();
  3. return $reuslt;
  4. });

Will result in the following structured result:

  1. {
  2. code: 200,
  3. result: "Success",
  4. message: "OK"
  5. }

Secondary Responses

This is response with result your send

  1. Route::get('/mess', function () {
  2. $array = array(
  3. 'first' => 'This is first data',
  4. 'second' => 'This is second data',
  5. );
  6. $reuslt = Message::success(200)->payload($array)->get();
  7. return $reuslt;
  8. });

Will result in the following structured result:

  1. {
  2. code: 200,
  3. result: "Informational",
  4. message: "OK",
  5. payload: {
  6. first: "This is first data",
  7. second: "This is second data"
  8. }
  9. }

Authors

*Muhammad Akil - Initial work - Akill

License

FOSSA Status

FOSSA Status

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc