mirror of https://github.com/4xmen/xshop.git
added slider with meta data values
parent
0c6148c84d
commit
991962ea43
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
@ -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>
|
@ -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> </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
|
Loading…
Reference in New Issue