mirror of https://github.com/4xmen/xshop.git
added tag translate name and model
parent
e0aff07b07
commit
68be86dd68
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Controllers\XController;
|
||||||
|
use App\Http\Requests\TagSaveRequest;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Spatie\Tags\Tag;
|
||||||
|
|
||||||
|
class TagController extends XController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $cols = ['name', 'slug'];
|
||||||
|
protected $extra_cols = ['id'];
|
||||||
|
|
||||||
|
protected $searchable = ['name', 'slug'];
|
||||||
|
|
||||||
|
protected $listView = 'admin.tags.tag-list';
|
||||||
|
|
||||||
|
|
||||||
|
protected $buttons = [
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(Tag::class, TagSaveRequest::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function makeSortAndFilter()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (!\request()->has('sort') || !in_array(\request('sort'), $this->cols)) {
|
||||||
|
$query = $this->_MODEL_::orderByDesc('id');
|
||||||
|
} else {
|
||||||
|
$query = $this->_MODEL_::orderBy(\request('sort'), \request('sortType', 'asc'));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (\request()->input('filter', []) as $col => $filter) {
|
||||||
|
if (isJson($filter)) {
|
||||||
|
$vals = json_decode($filter);
|
||||||
|
if (count($vals) != 0) {
|
||||||
|
$query->whereIn($col, $vals);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$query->where($col, $filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mb_strlen(trim(\request()->input('q', ''))) > 0) {
|
||||||
|
$q = trim(json_encode(\request()->input('q', '')), ' "');
|
||||||
|
$q = str_replace('\\', '\\\\', $q);
|
||||||
|
foreach ($this->searchable as $col) {
|
||||||
|
$query->where(function ($query) use ($q) {
|
||||||
|
foreach ($this->searchable as $key => $col) {
|
||||||
|
if ($key === 0) {
|
||||||
|
$query->where($col, 'LIKE', '%' . $q . '%');
|
||||||
|
} else {
|
||||||
|
$query->orWhere($col, 'LIKE', '%' . $q . '%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class TagSaveRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
@extends('admin.templates.panel-list-template')
|
||||||
|
|
||||||
|
@section('list-title')
|
||||||
|
<i class="ri-user-3-line"></i>
|
||||||
|
{{__("Tags list")}}
|
||||||
|
@endsection
|
||||||
|
@section('title')
|
||||||
|
{{__("Tags list")}} -
|
||||||
|
@endsection
|
||||||
|
@section('filter')
|
||||||
|
{{-- Other filters --}}
|
||||||
|
@endsection
|
||||||
|
@section('bulk')
|
||||||
|
{{-- <option value="-"> - </option> --}}
|
||||||
|
@endsection
|
Loading…
Reference in New Issue