40 lines
966 B
PHP
40 lines
966 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Base;
|
|
|
|
use App\Const\Responses;
|
|
use Illuminate\Routing\Controller;
|
|
|
|
class BaseController extends Controller
|
|
{
|
|
public array $validateMethodParams = [];
|
|
|
|
function __call($method, $parameters)
|
|
{
|
|
if (isset($this->validateMethodParams[$method])) {
|
|
$a = request()->validate($this->validateMethodParams[$method]);
|
|
}
|
|
parent::__call($method, $parameters);
|
|
}
|
|
|
|
function reply($code, $msg, $data = []): \Illuminate\Http\JsonResponse
|
|
{
|
|
return response()->json([
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
|
|
function success($data = []): \Illuminate\Http\JsonResponse
|
|
{
|
|
return $this->reply(Responses::CODE_SUCCESS, 'success', $data);
|
|
}
|
|
|
|
function error($msg = 'error', $data = []): \Illuminate\Http\JsonResponse
|
|
{
|
|
return $this->reply(Responses::CODE_ERROR, $msg, $data);
|
|
}
|
|
|
|
}
|