login
This commit is contained in:
39
app/Http/Controllers/Base/BaseController.php
Normal file
39
app/Http/Controllers/Base/BaseController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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])) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user