Code variables type declaration

This commit is contained in:
BrettonYe
2025-01-01 14:49:14 +08:00
parent b5628a4ab9
commit 08d20d07b8
56 changed files with 694 additions and 795 deletions

View File

@@ -8,53 +8,49 @@ use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Log;
use Response;
use Validator;
class SsConfigController extends Controller
{
// 添加SS配置
public function store(Request $request): JsonResponse
{
{ // 添加SS配置
$validator = Validator::make($request->all(), [
'name' => 'required|string|unique:ss_config,name',
'type' => 'required|numeric|between:1,3',
]);
if ($validator->fails()) {
return Response::json(['status' => 'fail', 'message' => $validator->errors()->all()]);
return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]);
}
if (SsConfig::create($validator->validated())) {
return Response::json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.add')])]);
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.add')])]);
}
return Response::json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.add')])]);
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.add')])]);
}
// 设置SS默认配置
public function update(SsConfig $ss): JsonResponse
{
{ // 设置SS默认配置
if ($ss->setDefault()) {
return Response::json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.edit')])]);
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.edit')])]);
}
return Response::json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.edit')])]);
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.edit')])]);
}
// 删除SS配置
public function destroy(SsConfig $ss): JsonResponse
{
{ // 删除SS配置
try {
if ($ss->delete()) {
return Response::json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.delete')])]);
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.delete')])]);
}
} catch (Exception $e) {
Log::error(trans('common.error_action_item', ['action' => trans('common.delete'), 'attribute' => trans('user.node.info')]).': '.$e->getMessage());
return Response::json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')]).', '.$e->getMessage()]);
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')]).', '.$e->getMessage()]);
}
return Response::json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')])]);
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')])]);
}
}