added slider with meta data values

pull/44/head
A1Gard 6 months ago
parent 0c6148c84d
commit 991962ea43

@ -123,6 +123,7 @@ class PostController extends XController
$this->_MODEL_::withTrashed()->find($id)->restore(); $this->_MODEL_::withTrashed()->find($id)->restore();
} }
break; break;
/*restore**/
case 'publish': case 'publish':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]); $this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]);
$msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]); $msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]);
@ -131,7 +132,6 @@ class PostController extends XController
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]); $this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]);
$msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]); $msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]);
break; break;
/*restore**/
default: default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]); $msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
} }

@ -0,0 +1,128 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\SliderSaveRequest;
use App\Models\Access;
use App\Models\Slider;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;
class SliderController extends XController
{
// protected $_MODEL_ = Slider::class;
// protected $SAVE_REQUEST = SliderSaveRequest::class;
protected $cols = ['body','status'];
protected $extra_cols = ['id','image'];
protected $searchable = ['body'];
protected $listView = 'admin.sliders.slider-list';
protected $formView = 'admin.sliders.slider-form';
protected $buttons = [
'edit' =>
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
'show' =>
['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
'destroy' =>
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];
public function __construct()
{
parent::__construct(Slider::class, SliderSaveRequest::class);
}
/**
* @param $slider Slider
* @param $request SliderSaveRequest
* @return Slider
*/
public function save($slider, $request)
{
$slider->body = $request->input('body', '');
$slider->status = $request->input('status');
$slider->data = $request->input('data');
$slider->user_id = auth()->id();
if ($request->hasFile('cover')) {
$name = time() . '.' . request()->cover->getClientOriginalExtension();
$slider->image = $name;
$request->file('cover')->storeAs('public/sliders', $name);
}
if ($request->has('cover')){
$slider->image = $this->storeFile('cover',$slider, 'sliders');
}
$slider->save();
return $slider;
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Slider $item)
{
//
return view($this->formView, compact('item'));
}
public function bulk(Request $request)
{
// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;
case 'publish':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 1]);
$msg = __(':COUNT items published successfully', ['COUNT' => count($ids)]);
break;
case 'draft':
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 0]);
$msg = __(':COUNT items drafted successfully', ['COUNT' => count($ids)]);
break;
default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}
return $this->do_bulk($msg, $action, $ids);
}
public function destroy(Slider $item)
{
return parent::delete($item);
}
public function update(Request $request, Slider $item)
{
return $this->bringUp($request, $item);
}
}

@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SliderSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'body' => ['required', 'string','min:1'],
'status' => ['required', 'boolean'],
'data'=> ['nullable'],
'cover' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:4096'],
];
}
}

@ -18,7 +18,7 @@ return new class extends Migration
$table->string('tag')->nullable(); $table->string('tag')->nullable();
$table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('user_id');
$table->unsignedTinyInteger('status')->default(0); $table->unsignedTinyInteger('status')->default(0);
$table->json('data'); $table->json('data')->nullable();
$table->timestamps(); $table->timestamps();
$table->foreign('user_id') $table->foreign('user_id')
->references('id')->on('users'); ->references('id')->on('users');

@ -52,7 +52,7 @@ app.component('vue-date-range-picker-input', vueDateRangePicker);
import SearchableSelect from "./components/SearchableSelect.vue"; import SearchableSelect from "./components/SearchableSelect.vue";
app.component('searchable-select', SearchableSelect); app.component('searchable-select', SearchableSelect);
import SearchableMultiSelect from "./components/searchableMultiSelect.vue"; import SearchableMultiSelect from "./components/SearchableMultiSelect.vue";
app.component('searchable-multi-select', SearchableMultiSelect); app.component('searchable-multi-select', SearchableMultiSelect);
import Increment from "./components/Increment.vue"; import Increment from "./components/Increment.vue";
@ -60,6 +60,9 @@ app.component('increment', Increment);
import TagInput from "./components/TagInput.vue"; import TagInput from "./components/TagInput.vue";
app.component('tag-input', TagInput); app.component('tag-input', TagInput);
import SliderData from "./components/SliderData.vue";
app.component('slider-data', SliderData);
/** /**
* The following block of code may be used to automatically register your * The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue * Vue components. It will recursively scan this directory for the Vue

@ -58,7 +58,7 @@ import CurrencyInput from "./CurrencyInput.vue";
import fontAwesomeIconPicker from "./FontAwesomeIconPicker.vue"; import fontAwesomeIconPicker from "./FontAwesomeIconPicker.vue";
import remixIconPicker from "./RemixIconPicker.vue"; import remixIconPicker from "./RemixIconPicker.vue";
import searchableSelect from "./SearchableSelect.vue"; import searchableSelect from "./SearchableSelect.vue";
import searchableMultiSelect from "./searchableMultiSelect.vue"; import SearchableMultiSelect from "./SearchableMultiSelect.vue";
import vueDateTimePicker from "./vueDateTimePicker.vue"; import vueDateTimePicker from "./vueDateTimePicker.vue";
import vueDateRangePicker from "./vueDateRangePicker.vue"; import vueDateRangePicker from "./vueDateRangePicker.vue";
import Increment from "./Increment.vue"; import Increment from "./Increment.vue";
@ -66,7 +66,7 @@ export default {
name: "example", name: "example",
components: { components: {
CurrencyInput, fontAwesomeIconPicker, remixIconPicker,Increment, CurrencyInput, fontAwesomeIconPicker, remixIconPicker,Increment,
searchableSelect, searchableMultiSelect, vueDateRangePicker, vueDateTimePicker searchableSelect, SearchableMultiSelect, vueDateRangePicker, vueDateTimePicker
}, },
data: () => { data: () => {
return { return {

@ -0,0 +1,72 @@
<template>
<div id="slider-data">
<div class="row">
<div class="col-4">
Keys:
</div>
<div class="col-8">
Values:
</div>
</div>
<div class="row mt-2" v-for="(val,i) in values">
<div class="col-4 px-1">
<input type="text" placeholder="key" v-model="val.key" class="form-control">
</div>
<div class="col-6 px-1">
<input type="text" placeholder="value" v-model="val.value" class="form-control">
</div>
<div class="col-2 text-center px-1">
<button class="btn btn-danger btn-sm" @click="remValue(i)" type="button">
<i class="ri-close-line"></i>
</button>
</div>
</div>
<br>
<button class="btn btn-secondary w-100" @click="addValue" type="button">
<i class="ri-add-line"></i>
</button>
<input type="hidden" name="data" :value="JSON.stringify(values)" >
</div>
</template>
<script>
export default {
name: "slider-data",
components: {},
data: () => {
return {
values:[]
}
},
props: {
dataz:{
type: Array,
default: [],
}
},
mounted() {
this.values = this.dataz;
},
computed: {
},
methods: {
addValue(){
this.values.push({
'key' : 'key' + (this.values.length + 1),
'value' : '',
});
},
remValue(i){
if (confirm('Are you sure?')){
this.values.splice(i,1);
}
}
}
}
</script>
<style scoped>
#slider-data {
padding: 1rem;
}
</style>

@ -11,5 +11,6 @@
{{-- Other filters --}} {{-- Other filters --}}
@endsection @endsection
@section('bulk') @section('bulk')
{{-- <option value="-"> - </option> --}} <option value="publish"> {{__("Publish")}} </option>
<option value="draft"> {{__("Draft")}} </option>
@endsection @endsection

@ -0,0 +1,104 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit slider")}} [{{$item->id}}]
@else
{{__("Add new slider")}}
@endif -
@endsection
@section('form')
<div class="row">
<div class="col-lg-3">
@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Recommends")}}
</li>
</ul>
</div>
@if(isset($item))
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Preview")}}
</h3>
<div class="p2 pb-5">
<img src="{{$item->imgUrl()}}" class="img-fluid" alt="image">
</div>
</div>
@endif
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Slider data")}}
</h3>
<div class="p2 pb-3">
<slider-data @if(isset($item)) :dataz='{{$item->data}}' @endif></slider-data>
</div>
</div>
</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">
<h1>
@if(isset($item))
{{__("Edit slider")}} [{{$item->id}}]
@else
{{__("Add new slider")}}
@endif
</h1>
<div class="row">
<div class="col-md-12 mt-3">
<div class="form-group">
<label for="body">
{{__('Description')}}
</label>
<textarea name="body" class="ckeditorx form-control @error('body') is-invalid @enderror"
placeholder="{{__('Description')}}">{{old('body',$item->body??null)}}</textarea>
</div>
</div>
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="status">
{{__('Status')}}
</label>
<select name="status" id="status"
class="form-control @error('status') is-invalid @enderror">
<option value="1"
@if (old('status',$item->status??null) == '1' ) selected @endif >{{__("Published")}} </option>
<option value="0"
@if (old('status',$item->status??null) == '0' ) selected @endif >{{__("Draft")}} </option>
</select>
</div>
</div>
<div class="col-md-6 mt-3">
<div class="form-group">
<label for="cover">
{{__('Image')}}
</label>
<input name="cover" id="cover" type="file"
accept="image/*"
class="form-control @error('cover') is-invalid @enderror"
placeholder="{{__('Image')}}"/>
</div>
</div>
<div class="col-md-12">
<label> &nbsp;</label>
<input name="" type="submit" class="btn btn-primary mt-2" value="{{__('Save')}}"/>
</div>
</div>
</div>
</div>
</div>
@endsection

@ -0,0 +1,17 @@
@extends('admin.templates.panel-list-template')
@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Sliders list")}}
@endsection
@section('title')
{{__("Sliders list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
<option value="publish"> {{__("Publish")}} </option>
<option value="draft"> {{__("Draft")}} </option>
@endsection

@ -157,7 +157,9 @@
</td> </td>
@if(isset($item) && method_exists($item,'imgUrl')) @if(isset($item) && method_exists($item,'imgUrl'))
<td> <td>
<a href="{{getRoute('edit',$item->{$item->getRouteKeyName()})}}">
<img src="{{$item->imgUrl()}}" class="image-x64" alt=""> <img src="{{$item->imgUrl()}}" class="image-x64" alt="">
</a>
</td> </td>
@endif @endif
@foreach($cols as $k => $col) @foreach($cols as $k => $col)
@ -165,7 +167,7 @@
<td> <td>
<a href="{{getRoute('edit',$item->{$item->getRouteKeyName()})}}"> <a href="{{getRoute('edit',$item->{$item->getRouteKeyName()})}}">
<b> <b>
{{$item?->{$cols[0]} }} {{strip_tags($item?->{$cols[0]}) }}
</b> </b>
</a> </a>
</td> </td>

@ -123,7 +123,7 @@
</a> </a>
</li> </li>
<li> <li>
<a> <a href="{{route('admin.slider.index')}}">
<i class="ri-image-fill"></i> <i class="ri-image-fill"></i>
{{__("Slider")}} {{__("Slider")}}
</a> </a>

@ -90,5 +90,17 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group(
Route::get('delete/{item}', [\App\Http\Controllers\Admin\GalleryController::class, 'destroy'])->name('destroy'); Route::get('delete/{item}', [\App\Http\Controllers\Admin\GalleryController::class, 'destroy'])->name('destroy');
Route::post('bulk', [\App\Http\Controllers\Admin\GalleryController::class, "bulk"])->name('bulk'); Route::post('bulk', [\App\Http\Controllers\Admin\GalleryController::class, "bulk"])->name('bulk');
}); });
Route::prefix('sliders')->name('slider.')->group(
function () {
Route::get('', [\App\Http\Controllers\Admin\SliderController::class, 'index'])->name('index');
Route::get('create', [\App\Http\Controllers\Admin\SliderController::class, 'create'])->name('create');
Route::post('store', [\App\Http\Controllers\Admin\SliderController::class, 'store'])->name('store');
Route::get('show/{item}', [\App\Http\Controllers\Admin\SliderController::class, 'show'])->name('show');
Route::post('title/update', [\App\Http\Controllers\Admin\SliderController::class, 'updateTitle'])->name('title');
Route::get('edit/{item}', [\App\Http\Controllers\Admin\SliderController::class, 'edit'])->name('edit');
Route::post('update/{item}', [\App\Http\Controllers\Admin\SliderController::class, 'update'])->name('update');
Route::get('delete/{item}', [\App\Http\Controllers\Admin\SliderController::class, 'destroy'])->name('destroy');
Route::post('bulk', [\App\Http\Controllers\Admin\SliderController::class, "bulk"])->name('bulk');
});
}); });
}); });

Loading…
Cancel
Save