bpartner/messages

API status messages

2.1.1 2019-05-06 11:34 UTC

This package is auto-updated.

Last update: 2024-11-19 01:54:40 UTC


README

Total Downloads Latest Stable Version PHP version

Set status message for API (REST, ajax ...).

Install with composer

$ composer require bpartner/messages

Get result for Rest API or ajax request

{
    "status": "success",
    "message": "Record updated",
    "data": {
        "id": 123,
        "name": "Test name"       
    }
}

Usage

Make status message

   $result = Messages::make();
   
   or
   
   $result = Messages::make('Default success message'); 
   
   or use facade ApiMessage
     
   $result = ApiMessage::setMessage('My message')
            ->setMeta($data)
            ->root('version', '1.0')
            ->get();

Add metadata to response status message

    $model = new Model();
    .....
    $result->setMeta($model);

Set Error Message

    $result->setErrorMessage('Error message');

Get message

    $result->get();

Response message in Controller with HTTP (200|400) status

    return $result->result();