added sort to menu items

pull/44/head
A1Gard 4 months ago
parent f1dec8db9f
commit 8188820ac3

@ -143,5 +143,22 @@ class MenuController extends XController
{
return parent::restoreing(Menu::withTrashed()->where('id', $item)->first());
}
public function sort(Menu $item){
return view('admin.menus.menu-sort', compact('item'));
}
public function sortSave(Request $request){
foreach ($request->input('items') as $key => $v){
$p = Item::whereId($v['id'])->first();
$p->sort = $key;
$p->save();
}
logAdmin(__METHOD__,__CLASS__,null);
return ['OK' => true,'message' => __("As you wished sort saved")];
}
/*restore**/
}

@ -14,6 +14,6 @@ class Menu extends Model
Category::class,Clip::class,Gallery::class];
public function items()
{
return $this->hasMany(Item::class);
return $this->hasMany(Item::class)->orderBy('sort');
}
}

@ -29,6 +29,30 @@
@endif
</ul>
</div>
@if(isset($item))
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-eye-2-line"></i>
{{__("Preview")}}
</h3>
<div class="p-2">
<ul class="list-group">
@foreach($item->items as $i)
<li class="list-group-item">
{{$i->title}}
</li>
@endforeach
</ul>
</div>
<div class="p-2 pt-0">
<a href="{{ route('admin.menu.sort',$item->id) }}" class="btn btn-primary w-100">
<i class="ri-sort-desc"></i>
{{__("Change items sort")}}
</a>
</div>
</div>
@endif
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">

@ -0,0 +1,26 @@
@extends('layouts.app')
@section('content')
<div id="sort-control">
<ol class="ol-sortable">
@foreach($item->items as $i)
<li data-id="{{$i->id}}" class="p-2">
<i class="ri-drag-move-2-line"></i>
{{$i->title}}
</li>
@endforeach
</ol>
</div>
<input type="hidden" id="sort-data" >
<button
data-link="{{getRoute('sort-save')}}"
id="save-sort"
class="action-btn circle-btn"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Save")}}"
>
<i class="ri-save-2-line"></i>
</button>
@endsection

@ -213,6 +213,8 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::get('restore/{item}', [\App\Http\Controllers\Admin\MenuController::class, 'restore'])->name('restore');
Route::post('bulk', [\App\Http\Controllers\Admin\MenuController::class, "bulk"])->name('bulk');
Route::get('trashed', [\App\Http\Controllers\Admin\MenuController::class, "trashed"])->name('trashed');
Route::post('sort/save', [\App\Http\Controllers\Admin\MenuController::class, 'sortSave'])->name('sort-save');
Route::get('sort/{item}', [\App\Http\Controllers\Admin\MenuController::class, 'sort'])->name('sort');
});
Route::prefix('states')->name('state.')->group(
function () {

Loading…
Cancel
Save