Controller.php 1012 字节
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * @param array $data
     * @param string $message
     * @param int $status
     * @return string
     */
    protected function success($data = [], $message = 'success', $status = 200)
    {
        $array = compact('status', 'message', 'data');
        return json_encode($array, JSON_UNESCAPED_UNICODE);
    }

    /**
     * @param int $status
     * @param string $message
     * @param array $data
     * @return string
     */
    protected function error($message = 'error', $status = 400, $data = [])
    {
        $array = compact('status', 'message', $data);
        return json_encode($array, JSON_UNESCAPED_UNICODE);
    }
}