<?php

namespace App\Traits;

trait HttpResponses {

    protected function success($data, string $message = null, int $code = 200)
    {
        return response()->json([
            'status' => 'Request was successful.',
            'message' => $message,
            'data' => $data
        ], $code,
        ['Content-type'=>'application/json;charset=utf-8'],JSON_UNESCAPED_UNICODE
        );
    }
    //->header('Content-Type', 'application/json; charset=utf-8')->header('Charset', 'utf-8')

    protected function error($data, string $message = null, int $code)
    {
        return response()->json([
            'status' => 'An error has occurred...',
            'message' => $message,
            'data' => $data
        ], $code);
    }

    protected function abort()
    {
        return response()->json([
            'status' => 'An error has occurred...',
            'message' => 'No record found',
            'data' => null,
        ], 404);
    }
}
