89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
|
// +----------------------------------------------------------------------
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
trait AdminController {
|
|
|
|
protected $service = null;
|
|
|
|
/**
|
|
* @title 列表
|
|
*
|
|
* @param Request $request
|
|
* @param $service
|
|
* @return void
|
|
*/
|
|
public function index(Request $request){
|
|
try {
|
|
$this->data['data'] = $this->service->getDataList($request);
|
|
} catch (\Throwable $th) {
|
|
$this->data['code'] = 0;
|
|
$this->data['message'] = $th->getMessage();
|
|
}
|
|
|
|
return response()->json($this->data);
|
|
}
|
|
|
|
/**
|
|
* @title 添加
|
|
*
|
|
* @param Request $request
|
|
* @param $service
|
|
* @return void
|
|
*/
|
|
public function add(Request $request){
|
|
try {
|
|
$this->data['data'] = $this->service->create($request);
|
|
} catch (\Throwable $th) {
|
|
$this->data['code'] = 0;
|
|
$this->data['message'] = $th->getMessage();
|
|
}
|
|
|
|
return response()->json($this->data);
|
|
}
|
|
|
|
/**
|
|
* @title 编辑
|
|
*
|
|
* @param Request $request
|
|
* @param $service
|
|
* @return void
|
|
*/
|
|
public function edit(Request $request){
|
|
try {
|
|
$this->data['data'] = $this->service->update($request);
|
|
} catch (\Throwable $th) {
|
|
$this->data['code'] = 0;
|
|
$this->data['message'] = $th->getMessage();
|
|
}
|
|
|
|
return response()->json($this->data);
|
|
}
|
|
|
|
/**
|
|
* @title 删除
|
|
*
|
|
* @param Request $request
|
|
* @param $service
|
|
* @return void
|
|
*/
|
|
public function delete(Request $request){
|
|
try {
|
|
$this->data['data'] = $this->service->delete($request);
|
|
} catch (\Throwable $th) {
|
|
$this->data['code'] = 0;
|
|
$this->data['message'] = $th->getMessage();
|
|
}
|
|
|
|
return response()->json($this->data);
|
|
}
|
|
}
|