添加友情链接管理
parent
afe617a23b
commit
1a74f7b1a1
|
|
@ -6,6 +6,9 @@ use App\Helpers\Paginator;
|
|||
use App\Http\Resources\FriendLinkResource;
|
||||
use App\Models\FriendLink;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requestes\FriendLinkRequest;
|
||||
use App\Services\OperationLogService;
|
||||
use App\Enums\OperationType;
|
||||
|
||||
class FriendLinkController extends Controller
|
||||
{
|
||||
|
|
@ -17,4 +20,34 @@ class FriendLinkController extends Controller
|
|||
|
||||
return $this->json(FriendLinkResource::collection($list));
|
||||
}
|
||||
|
||||
public function store(FriendLinkRequest $request){
|
||||
$input = $request->input();
|
||||
|
||||
$friendLink = FriendLink::create($input);
|
||||
|
||||
(new OperationLogService())->inLog(OperationType::Create, '', $friendLink, $request->input());
|
||||
|
||||
return $this->success('添加成功');
|
||||
}
|
||||
|
||||
public function show(FriendLink $friendLink){
|
||||
return $this->json(FriendLinkResource::make($friendLink));
|
||||
}
|
||||
|
||||
public function update(FriendLink $friendLink, FriendLinkRequest $request){
|
||||
$friendLink->update($request->input());
|
||||
|
||||
(new OperationLogService())->inLog(OperationType::Update, '', $friendLink, $request->input());
|
||||
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
|
||||
public function destroy(FriendLink $friendLink){
|
||||
$friendLink->delete();
|
||||
|
||||
(new OperationLogService())->inLog(OperationType::Delete, '', $friendLink);
|
||||
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class WebController extends Controller
|
||||
{
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$path = $request->input('path', 'uploads') . '/' . date('Y-m-d');
|
||||
$result = [];
|
||||
|
||||
$disk = $this->getDisk();
|
||||
|
||||
// file 文件
|
||||
$files = $request->except('path');
|
||||
foreach ($files as $key => $fileData) {
|
||||
$item = null;
|
||||
if (is_array($fileData)) {
|
||||
foreach ($fileData as $file) {
|
||||
$item[] = $disk->url($this->saveFile($disk, $path, $file));
|
||||
}
|
||||
} else {
|
||||
$item = $disk->url($this->saveFile($disk, $path, $fileData));
|
||||
}
|
||||
$result[$key] = $item;
|
||||
}
|
||||
return $this->json($result);
|
||||
}
|
||||
|
||||
protected function saveFile($disk, $path, $file = null)
|
||||
{
|
||||
$filePath = '';
|
||||
if ($file instanceof UploadedFile) {
|
||||
$filePath = $disk->putFile($path, $file);
|
||||
} elseif (preg_match('/^(data:\s*image\/(\w+);base64,)/', $file, $result)) {
|
||||
$type = $result[2];
|
||||
if (in_array($type, ['jpeg', 'jpg', 'gif', 'bmp', 'png'])) {
|
||||
$filePath = $path . '/' . uniqid() . '.' . $type;
|
||||
$disk->put($filePath, base64_decode(str_replace($result[1], '', $file)));
|
||||
}
|
||||
}
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
protected function getDisk($disk = null): Filesystem
|
||||
{
|
||||
return Storage::disk($disk);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requestes;
|
||||
|
||||
use App\Enums\DeviceType;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class FriendLinkRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'type' => 'required|integer|min:1|max:3',
|
||||
'content' => 'required',
|
||||
'sort' => 'required|integer',
|
||||
'is_recommend' => 'required|boolean',
|
||||
'is_show'=> 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$messages = [
|
||||
'name' => '请填写标题',
|
||||
'type' => '请选择类型',
|
||||
'content' => '请填充内容',
|
||||
'sort' => '请填写排序',
|
||||
'is_recommend' => '请设置推荐',
|
||||
'is_show' => '请设置显示'
|
||||
];
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
$error = $validator->errors()->all();
|
||||
throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]]));
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ class FriendLinkResource extends JsonResource
|
|||
'type' => $this->type,
|
||||
'content' => $this->content,
|
||||
'sort' => $this->sort,
|
||||
'is_recommend' => $this->is_recommend,
|
||||
'is_show' => $this->is_show,
|
||||
'created_at' => strtotime($this->created_at) ?? 0, //录入时间
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ use Illuminate\Support\Facades\Route;
|
|||
Route::post('auth/login', [AuthController::class, 'login']);
|
||||
|
||||
Route::group(['middleware' => 'auth:sanctum'], function () {
|
||||
|
||||
Route::post('web/upload', [WebController::class, 'upload']);
|
||||
|
||||
Route::get('keywords-crops', [KeywordController::class, 'crops']); //农作物
|
||||
Route::get('keywords-crops-cate', [KeywordController::class, 'cropsCate']); //农作物产业分类
|
||||
Route::get('permissions', [AdminPermissionController::class, 'index']);
|
||||
|
|
@ -57,7 +60,7 @@ Route::group(['middleware' => 'auth:sanctum'], function () {
|
|||
Route::get('device-warning-nums', [DeviceWarningController::class, 'warningLogNum']);
|
||||
|
||||
//友情链接
|
||||
Route::apiResource('friend-links', FriendLinkController::class)->only(['index'])->names('friend_links');
|
||||
Route::apiResource('friend-links', FriendLinkController::class)->names('friend_links');
|
||||
|
||||
//操作日志
|
||||
Route::apiResource('operation-logs', OperationLogController::class)->only(['index'])->names('operation_logs');
|
||||
|
|
|
|||
Loading…
Reference in New Issue