mirror of https://github.com/4xmen/xshop.git
parent
342f1f91c4
commit
a20dc80748
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\AdvSaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\Adv;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class AdvController extends XController
|
||||
{
|
||||
|
||||
// protected $_MODEL_ = Adv::class;
|
||||
// protected $SAVE_REQUEST = AdvSaveRequest::class;
|
||||
|
||||
protected $cols = ['title','link'];
|
||||
protected $extra_cols = ['id','image'];
|
||||
|
||||
protected $searchable = ['title','link'];
|
||||
|
||||
protected $listView = 'admin.advs.adv-list';
|
||||
protected $formView = 'admin.advs.adv-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(Adv::class, AdvSaveRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $adv Adv
|
||||
* @param $request AdvSaveRequest
|
||||
* @return Adv
|
||||
*/
|
||||
public function save($adv, $request)
|
||||
{
|
||||
|
||||
$adv->title = $request->input('title');
|
||||
$adv->max_click = $request->input('max_click');
|
||||
$adv->link = $request->input('link');
|
||||
$adv->expire = date('Y-m-d',$request->input('expire'));
|
||||
$adv->user_id = auth()->id();
|
||||
$adv->status = $request->input('status');
|
||||
|
||||
if ($request->has('image')){
|
||||
$adv->image = $this->storeFile('image',$adv, 'ad');
|
||||
}
|
||||
|
||||
$adv->save();
|
||||
return $adv;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(Adv $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;
|
||||
/**restore*/
|
||||
case 'restore':
|
||||
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]);
|
||||
foreach ($ids as $id) {
|
||||
$this->_MODEL_::withTrashed()->find($id)->restore();
|
||||
}
|
||||
break;
|
||||
/*restore**/
|
||||
default:
|
||||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
|
||||
}
|
||||
|
||||
return $this->do_bulk($msg, $action, $ids);
|
||||
}
|
||||
|
||||
public function destroy(Adv $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Adv $item)
|
||||
{
|
||||
return $this->bringUp($request, $item);
|
||||
}
|
||||
|
||||
/**restore*/
|
||||
public function restore($item)
|
||||
{
|
||||
return parent::restoreing(Adv::withTrashed()->where('id', $item)->first());
|
||||
}
|
||||
/*restore**/
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdvSaveRequest 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 [
|
||||
//
|
||||
'title' => ['required', 'string', 'max:255','min:5'],
|
||||
'link' => ['required', 'string', 'max:255','min:5'],
|
||||
'status' => ['required', 'boolean'],
|
||||
'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
|
||||
'max_click' => ['required','numeric'],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
@extends('admin.templates.panel-form-template')
|
||||
@section('title')
|
||||
@if(isset($item))
|
||||
{{__("Edit adv")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new adv")}}
|
||||
@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>
|
||||
{{__("Max click zero is unlimited")}}
|
||||
</li>
|
||||
<li>
|
||||
{{__("If not choose expire expire time will be unlimited")}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@if (isset($item))
|
||||
<div class="item-list mb-3">
|
||||
<h3 class="p-3">
|
||||
<i class="ri-image-2-line"></i>
|
||||
{{__("Image")}}
|
||||
</h3>
|
||||
<div class="pb-4">
|
||||
<img src="{{$item->imgUrl()}}" class="img-fluid" alt="{{$item->title}}">
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
|
||||
<div class="general-form ">
|
||||
|
||||
<h1>
|
||||
@if(isset($item))
|
||||
{{__("Edit adv")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new adv")}}
|
||||
@endif
|
||||
</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="title">
|
||||
{{__('Title')}}
|
||||
</label>
|
||||
<input name="title" type="text" class="form-control @error('title') is-invalid @enderror" placeholder="{{__('Title')}}" value="{{old('title',$item->title??null)}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="link">
|
||||
{{__('Link')}}
|
||||
</label>
|
||||
<input name="link" type="url" class="form-control @error('link') is-invalid @enderror" placeholder="{{__('Link')}}" value="{{old('link',$item->link??null)}}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3 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-4 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="image">
|
||||
{{__('Image')}}
|
||||
</label>
|
||||
<input name="image" type="file" class="form-control @error('image') is-invalid @enderror" placeholder="{{__('Image')}}" accept="image/*" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-5 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="max_click">
|
||||
{{__('Max click')}}
|
||||
</label>
|
||||
<input name="max_click" type="number" class="form-control @error('max_click') is-invalid @enderror" placeholder="{{__('Max click')}}" value="{{old('max_click',$item->max_click??0)}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 mt-3">
|
||||
<label for="dp">
|
||||
{{__("Expire")}}
|
||||
</label>
|
||||
{{-- WIP for lang change def tab--}}
|
||||
<vue-datetime-picker-input :xmin="{{strtotime('yesterday')}}"
|
||||
xid="dp" xname="expire" xshow="date" xtitle="Expire date" def-tab="1"
|
||||
@if(isset($item)) :xvalue="{{strtotime($item->expire)}}" @endif
|
||||
></vue-datetime-picker-input>
|
||||
</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,15 @@
|
||||
@extends('admin.templates.panel-list-template')
|
||||
|
||||
@section('list-title')
|
||||
<i class="ri-user-3-line"></i>
|
||||
{{__("Advs list")}}
|
||||
@endsection
|
||||
@section('title')
|
||||
{{__("Advs list")}} -
|
||||
@endsection
|
||||
@section('filter')
|
||||
{{-- Other filters --}}
|
||||
@endsection
|
||||
@section('bulk')
|
||||
{{-- <option value="-"> - </option> --}}
|
||||
@endsection
|
Loading…
Reference in New Issue