VersionController.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Http\Container\AdminSection\Controllers\System;
use App\Helpers\OperationLog;
use App\Http\Container\AdminSection\Requests\System\VersionRequest;
use App\Models\AppVersion;
use Auth;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\Request;
class VersionController extends ApiController
{
/**
* @param \Illuminate\Http\Request $request
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function index(Request $request): Response
{
$pageSize = $request->get('pageSize', 20);
$filter = $request->except(['page', 'pageSize']);
$data = AppVersion::filter($filter)->paginate($pageSize);
return $this->successWithData($data);
}
/**
* @param \App\Http\Container\AdminSection\Requests\System\VersionRequest $request
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function store(VersionRequest $request): Response
{
$version = AppVersion::query()->create($request->safe()->merge(['user_id' => Auth::id()])->toArray());
OperationLog::admin()->createAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));
return $this->successWithData($version, ApiCode::CREATE_SUCCESS);
}
/**
* @param \App\Http\Container\AdminSection\Requests\System\VersionRequest $request
* @param \App\Models\AppVersion $version
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function update(VersionRequest $request, AppVersion $version): Response
{
$version->update($request->safe()->toArray());
OperationLog::admin()->updateAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));
return $this->successWithData($version, ApiCode::UPDATE_SUCCESS);
}
/**
* @param \App\Models\AppVersion $version
* @return \Hikoon\LaravelApi\Facades\Response
*/
public function destroy(AppVersion $version): Response
{
$version->delete();
OperationLog::admin()->deleteAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));
return $this->success(ApiCode::DELETE_SUCCESS);
}
}