mirror of https://github.com/4xmen/xshop.git
parent
aa974c76c3
commit
f864f8cf4a
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\GallerySaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\Gallery;
|
||||
use App\Models\Image;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class GalleryController extends XController
|
||||
{
|
||||
|
||||
// protected $_MODEL_ = Gallery::class;
|
||||
// protected $SAVE_REQUEST = GallerySaveRequest::class;
|
||||
|
||||
protected $cols = ['title','status'];
|
||||
protected $extra_cols = ['id','slug'];
|
||||
|
||||
protected $searchable = ['title','description'];
|
||||
|
||||
protected $listView = 'admin.galleries.gallery-list';
|
||||
protected $formView = 'admin.galleries.gallery-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(Gallery::class, GallerySaveRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $gallery Gallery
|
||||
* @param $request GallerySaveRequest
|
||||
* @return Gallery
|
||||
*/
|
||||
public function save($gallery, $request)
|
||||
{
|
||||
|
||||
$gallery->title = $request->input('title');
|
||||
$gallery->slug = $this->getSlug($gallery,'slug','title');
|
||||
$gallery->description = $request->input('description');
|
||||
$gallery->status = $request->input('status');
|
||||
$gallery->user_id = auth()->id();
|
||||
|
||||
$gallery->save();
|
||||
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$gallery->media()->delete();
|
||||
$gallery->addMedia($request->file('image'))
|
||||
->preservingOriginal() //middle method
|
||||
->toMediaCollection();
|
||||
}
|
||||
$gallery->save();
|
||||
return $gallery;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(Gallery $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(Gallery $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Gallery $item)
|
||||
{
|
||||
return $this->bringUp($request, $item);
|
||||
}
|
||||
|
||||
|
||||
public function updateTitle(Request $request){
|
||||
foreach ($request->titles as $k => $title) {
|
||||
$image = Image::whereId($k)->first();
|
||||
$image->title = $title;
|
||||
$image->save();
|
||||
}
|
||||
return redirect()->back()->with(['message' => __("Titles updated")]);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Gallery;
|
||||
use App\Models\Image;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ImageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, Gallery $gallery)
|
||||
{
|
||||
|
||||
|
||||
foreach ($request->file('image') as $k => $item) {
|
||||
|
||||
DB::transaction(function () use ($gallery, $item, $request): void {
|
||||
|
||||
$newimage = $gallery->images()->create([
|
||||
'title' => $gallery->title . '-' . ($gallery->images()->count() + 1),
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
$newimage->addMedia($item)
|
||||
->toMediaCollection();
|
||||
});
|
||||
}
|
||||
logAdmin(__METHOD__, Gallery::class, $gallery->id);
|
||||
|
||||
return redirect()->back()->with(['message' => __(':COUNT Images uploaded successfully', ['COUNT' => count($request->file('image'))] )]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Image $image)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Image $image)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Image $image)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Image $image)
|
||||
{
|
||||
//
|
||||
logAdmin(__METHOD__, Image::class, $image->id);
|
||||
$image->delete();
|
||||
return redirect()->back()->with(['message' => __('Image deleted successfully')]);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class GallerySaveRequest 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:2'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'status' => ['required', 'boolean'],
|
||||
'image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class Image extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory,InteractsWithMedia, HasTranslations;
|
||||
public $translatable = ['title'];
|
||||
|
||||
protected $guarded = [''];
|
||||
|
||||
public function gallery()
|
||||
{
|
||||
return $this->belongsTo(Gallery::class, 'gallery_id');
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null): void
|
||||
{
|
||||
|
||||
$t = explode('x', config('starter-kit.post_thumb'));
|
||||
if (config('starter-kit.gallery_thumb') == null || config('starter-kit.gallery_thumb') == '') {
|
||||
$t[0] = 500;
|
||||
$t[1] = 500;
|
||||
}
|
||||
|
||||
$this->addMediaConversion('image-image')->optimize();
|
||||
|
||||
$this->addMediaConversion('gthumb')->width($t[0])
|
||||
->height($t[1])
|
||||
->nonQueued()
|
||||
->crop( $t[0], $t[1])->optimize();
|
||||
// ->watermark(public_path('images/logo.png'))->watermarkOpacity(50);
|
||||
// ->withResponsiveImages();
|
||||
}
|
||||
|
||||
public function imgurl()
|
||||
{
|
||||
if ($this->getMedia()->count() > 0) {
|
||||
return $this->getMedia()->first()->getUrl('gthumb');
|
||||
} else {
|
||||
return "no image";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
@extends('admin.templates.panel-form-template')
|
||||
@section('title')
|
||||
@if(isset($item))
|
||||
{{__("Edit gallery")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new gallery")}}
|
||||
@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>
|
||||
{{__("You can add images after create gallery")}}
|
||||
</li>
|
||||
<li>
|
||||
{{__("You can choose more than image to upload")}}
|
||||
</li>
|
||||
<li>
|
||||
{{__("We recommending add title each images")}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@if (isset($item))
|
||||
<div class="item-list mb-3">
|
||||
<h3 class="p-3">
|
||||
<i class="ri-image-2-line"></i>
|
||||
{{__("Index 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 gallery")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new gallery")}}
|
||||
@endif
|
||||
</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="title">
|
||||
{{__('Title')}}
|
||||
</label>
|
||||
<input name="title" type="text" id="title"
|
||||
class="form-control @error('title') is-invalid @enderror"
|
||||
placeholder="{{__('Title')}}" value="{{old('title',$item->title??null)}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="description">
|
||||
{{__('Description')}}
|
||||
</label>
|
||||
<textarea id="description" name="description"
|
||||
class="form-control @error('description') is-invalid @enderror"
|
||||
placeholder="{{__('Description')}}"
|
||||
rows="3">{{old('description',$item->description??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="image">
|
||||
{{__('Index image')}}
|
||||
</label>
|
||||
<input name="image" accept=".jpg,.png,.jpeg,.gif,.svg" type="file"
|
||||
class="form-control @error('image') is-invalid @enderror"
|
||||
placeholder="{{__('Index image')}}" value="{{old('image',$item->image??null)}}"/>
|
||||
</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
|
||||
@section('out-of-form')
|
||||
@if (isset($item))
|
||||
@if($item->images->count() > 0)
|
||||
|
||||
<div class="card mt-3">
|
||||
<div class="card-header">
|
||||
{{__("Images")}}
|
||||
</div>
|
||||
<form action="{{route('admin.gallery.title',$item->slug)}}" method="post">
|
||||
<div class="card-body">
|
||||
@csrf
|
||||
<div class="row">
|
||||
|
||||
@foreach($item->images as $img)
|
||||
<div class="col-md-3">
|
||||
<a href="{{route('admin.image.destroy',$img->id)}}" class="btn btn-danger delete-confirm rm-img ms-2">
|
||||
<i class="ri-delete-bin-6-line"></i>
|
||||
</a>
|
||||
<img src="{{$img->imgUrl()}}" class="img-squire" alt="">
|
||||
<div class="row mt-2">
|
||||
<div class="col-md-10">
|
||||
<input type="text" class="form-control" name="titles[{{$img->id}}]"
|
||||
value="{{$img->title}}"/>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
@if(config('app.xlang'))
|
||||
<a href="{{route('admin.lang.model',[$img->id,\Xmen\StarterKit\Models\Image::class])}}"
|
||||
class="btn btn-outline-dark translat-btn">
|
||||
<i class="ri-translate"></i>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<input type="submit" class="btn btn-primary" value="{{__("Save")}}"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="pb-5">
|
||||
<form class="card mt-3 mb-5" method="post" enctype="multipart/form-data"
|
||||
action="{{route('admin.image.store',$item->slug)}}">
|
||||
@csrf
|
||||
<div class="card-header">
|
||||
{{__("Upload new images")}}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<input type="file" class="form-control" name="image[]" multiple accept="image/*"
|
||||
id="gallery_images"/>
|
||||
<ul id="newimgs">
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<input type="submit" class="btn btn-dark" value="{{__("Upload images")}}"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
@ -0,0 +1,16 @@
|
||||
@extends('admin.templates.panel-list-template')
|
||||
|
||||
@section('list-title')
|
||||
<i class="ri-user-3-line"></i>
|
||||
{{__("Galleries list")}}
|
||||
@endsection
|
||||
@section('title')
|
||||
{{__("Galleries list")}} -
|
||||
@endsection
|
||||
@section('filter')
|
||||
{{-- Other filters --}}
|
||||
@endsection
|
||||
@section('bulk')
|
||||
<option value="publish"> {{__("Publish")}} </option>
|
||||
<option value="draft"> {{__("Draft")}} </option>
|
||||
@endsection
|
Loading…
Reference in New Issue