[WIP] Add thumb on offers, refactor categories, try to fix counter on relations polymorphic with eage loader, bad pattern !

This commit is contained in:
Ludovic CANDELLIER
2021-12-17 00:30:07 +01:00
parent cb0b2e4aa0
commit 8a1573d425
26 changed files with 171 additions and 107 deletions

View File

@@ -12,20 +12,24 @@ class CategoriesDataTable extends DataTable
public function query(Category $model) public function query(Category $model)
{ {
$model = $model::with(['tags.articles'])->withCount(['articles', 'tags']); $model = $model::with(['tags.articles'])->withCount(['articles','tags']);
return $this->buildQuery($model); return $this->buildQuery($model);
} }
public function modifier($datatables) public function modifier($datatables)
{ {
$datatables $datatables
->editColumn('name', function (Category $category) {
return $category->name;
})
->editColumn('visible', function (Category $category) { ->editColumn('visible', function (Category $category) {
return view("components.form.toggle", [ return view("components.form.toggle", [
'name' => 'visible',
'value' => $category->visible, 'value' => $category->visible,
'on' => __('visible'), 'on' => __('visible'),
'off' => __('invisible'), 'off' => __('invisible'),
'meta' => 'data-id=' . $category->id, 'meta' => 'data-id=' . $category->id,
'size' => 'sm', 'size' => 'xs',
]); ]);
}) })
->editColumn('articles_tagged_count', function (Category $category) { ->editColumn('articles_tagged_count', function (Category $category) {
@@ -45,9 +49,9 @@ class CategoriesDataTable extends DataTable
return [ return [
Column::make('visible')->title('visible')->width(60)->title(''), Column::make('visible')->title('visible')->width(60)->title(''),
Column::make('name')->title('Nom'), Column::make('name')->title('Nom'),
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false)->width(60), Column::make('articles_count')->title('#Art')->class('text-right')->orderable(false)->searchable(false)->width(60),
Column::make('tags_count')->title('#Tags')->class('text-right')->searchable(false)->width(60), Column::make('tags_count')->title('#Tags')->class('text-right')->searchable(false)->width(60),
Column::make('articles_tagged_count')->title('#ArtTag')->class('text-right')->searchable(false)->width(60), Column::make('articles_tagged_count')->title('#ArtTag')->class('text-right')->searchable(false)->orderable(false)->width(60),
$this->makeColumnButtons(), $this->makeColumnButtons(),
]; ];
} }

View File

@@ -5,6 +5,7 @@ namespace App\Datatables\Shop;
use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable; use App\Datatables\ParentDataTable as DataTable;
use App\Models\Shop\Offer; use App\Models\Shop\Offer;
use App\Repositories\Shop\Offers;
class OffersDataTable extends DataTable class OffersDataTable extends DataTable
{ {
@@ -34,6 +35,9 @@ class OffersDataTable extends DataTable
public function modifier($datatables) public function modifier($datatables)
{ {
$datatables $datatables
->editColumn('thumb', function (Offer $offer) {
return '<img src="' . Offers::getThumbSrc($offer) . '">';
})
->editColumn('status_id', function (Offer $offer) { ->editColumn('status_id', function (Offer $offer) {
return view("components.form.toggle", [ return view("components.form.toggle", [
'value' => $offer->status_id, 'value' => $offer->status_id,
@@ -46,7 +50,7 @@ class OffersDataTable extends DataTable
->editColumn('stock_delayed', function (Offer $offer) { ->editColumn('stock_delayed', function (Offer $offer) {
return $offer->stock_delayed . ' - ' . $offer->delay_type; return $offer->stock_delayed . ' - ' . $offer->delay_type;
}) })
->rawColumns(['active', 'action']); ->rawColumns(['active', 'thumb', 'action']);
return parent::modifier($datatables); return parent::modifier($datatables);
} }
@@ -55,6 +59,7 @@ class OffersDataTable extends DataTable
return [ return [
Column::make('status_id')->title('')->width(40), Column::make('status_id')->title('')->width(40),
Column::make('article.article_nature.name')->title('Nature'), Column::make('article.article_nature.name')->title('Nature'),
Column::make('thumb')->title('')->width(40),
Column::make('article.name')->title('Article'), Column::make('article.name')->title('Article'),
Column::make('variation.name')->title('Déclinaison'), Column::make('variation.name')->title('Déclinaison'),
Column::make('tariff.name')->title('Tarif'), Column::make('tariff.name')->title('Tarif'),

View File

@@ -36,7 +36,9 @@ class CustomerController extends Controller
public function edit($id) public function edit($id)
{ {
$data['customer'] = Customers::get($id)->toArray(); $data['customer'] = Customers::edit($id);
dump($data['customer']);
exit;
$data['deliveries'] = Deliveries::getOptions(); $data['deliveries'] = Deliveries::getOptions();
return view('Admin.Shop.Customers.edit', $data); return view('Admin.Shop.Customers.edit', $data);
} }

View File

@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Repositories\Shop\Categories; use App\Repositories\Shop\Categories;
use App\Repositories\Shop\Offers; use App\Repositories\Shop\Offers;
use App\Repositories\Shop\Tags;
class CategoryController extends Controller class CategoryController extends Controller
{ {
@@ -18,8 +19,11 @@ class CategoryController extends Controller
public function show($id) public function show($id)
{ {
$data = self::init(); $data = self::init();
$data['category'] = Categories::getByCategory($id)->toArray(); $data['category'] = Categories::getFull($id);
$data['offers'] = Offers::getByCategory($id)->toArray(); $data['offers'] = Offers::getByCategoryWithTags($id);
$data['tags'] = Tags::getWithCountOffers();
dump($data);
exit;
return view('Shop.shelve', $data); return view('Shop.shelve', $data);
} }

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models\Core;
use Rinvex\Categories\Models\Category as parentCategory;
use App\Models\Shop\Article;
class Category extends parentCategory
{
public function Articles()
{
// return $this->entries(Article::class);
return $this->morphedByMany(Article::class, 'categorizable');
}
}

View File

@@ -8,18 +8,19 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media; use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Translatable\HasTranslations;
// use Rinvex\Categories\Traits\Categorizable; // use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable; use Rinvex\Tags\Traits\Taggable;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Wildside\Userstamps\Userstamps; use Wildside\Userstamps\Userstamps;
class Category extends Model class Category extends Model
{ {
use InteractsWithMedia, SoftDeletes, Taggable, Userstamps; use HasTranslations, InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
protected $guarded = ['id']; protected $guarded = ['id'];
protected $table = 'shop_categories'; protected $table = 'categories';
public $translatable = ['name','description'];
public function Articles() public function Articles()
{ {
@@ -31,14 +32,9 @@ class Category extends Model
return $this->tags->articles; return $this->tags->articles;
} }
public function Shelves() public function countArticlesTagged()
{ {
return $this->morphedByMany(Category::class, 'categorizable'); return $this->tags()->withCount('Articles');
}
public function CategoryTree()
{
return $this->belongsTo(app('rinvex.categories.category'), 'category_id');
} }
public function scopeByCategory($query, $category_id) public function scopeByCategory($query, $category_id)

View File

@@ -23,9 +23,9 @@ class Offer extends Model
return $this->article->categories(); return $this->article->categories();
} }
public function variation() public function tags()
{ {
return $this->belongsTo(Variation::class); return $this->article->tags();
} }
public function tariff() public function tariff()
@@ -33,6 +33,11 @@ class Offer extends Model
return $this->belongsTo(Tariff::class); return $this->belongsTo(Tariff::class);
} }
public function variation()
{
return $this->belongsTo(Variation::class);
}
public function scopeByArticle($query, $id) public function scopeByArticle($query, $id)
{ {
return $query->where('article_id', $id); return $query->where('article_id', $id);
@@ -64,6 +69,20 @@ class Offer extends Model
return $query->where('status_id', $id); return $query->where('status_id', $id);
} }
public function scopeByTag($query, $tag_id)
{
return $query->whereHas('article.tags', function ($query) use ($tag_id) {
$query->where('tag_id', $tag_id);
});
}
public function scopeByTags($query, $tags)
{
return $query->whereHas('article.tags', function ($query) use ($tags) {
$query->whereIn('tag_id', $tags);
});
}
public function scopeByVariation($query, $id) public function scopeByVariation($query, $id)
{ {
return $query->where('variation_id', $id); return $query->where('variation_id', $id);

View File

@@ -24,6 +24,12 @@ class Tag extends parentTag
} }
*/ */
// TODO
public function offers()
{
return $this->articles();
}
public function articles() public function articles()
{ {
return $this->morphedByMany(Article::class, 'taggable'); return $this->morphedByMany(Article::class, 'taggable');

View File

@@ -1,48 +0,0 @@
<?php
namespace App\Repositories\Core;
use TheSeer\DirectoryScanner\DirectoryScanner;
class Cache
{
public static function getAutoVersion($file)
{
$filePath = public_path() . $file;
if (!file_exists($filePath)) {
return '';
}
$version = filemtime($filePath);
return '?v=' . $version;
}
public static function getFilesVersion($folder, $type)
{
$folder = str_replace('.', '/', $folder);
// dump($folder);
// dump($type);
// exit;
$scanner = new DirectoryScanner;
$scanner->addInclude('*.'.$type);
// $scanner->addExclude('*filter*');
// $scanner->addExclude('./src/*');
$path = public_path() . '/' . $folder;
$data = [];
foreach ($scanner($path) as $i) {
// dump($i);
$sub = $i->getPath();
$sub = str_replace($path, '', $sub);
$sub = str_replace('\\', '/', $sub);
// dump($sub);
$filename = '/' . $folder . $sub . '/' . $i->getFilename();
// dump($filename);
$mtime = $i->getMTime();
$data[$filename] = $mtime;
}
return $data;
}
}

View File

@@ -1,10 +1,10 @@
<?php <?php
namespace App\Repositories\Shop; namespace App\Repositories\Core;
use App\Repositories\Core\Arrays; use App\Repositories\Core\Arrays;
class CategoryTrees class Categories
{ {
public static function getTree($withFolder = false) public static function getTree($withFolder = false)
{ {
@@ -74,9 +74,9 @@ class CategoryTrees
public static function update($data, $id = false) public static function update($data, $id = false)
{ {
$id = $id ? $id : $data['category_id']; $id = $id ? $id : $data['id'];
$item = self::getNode($id); $item = self::getNode($id);
$item->update(['name' => $data['name']]); $item->update($data);
return $item; return $item;
} }

View File

@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
use App\Models\Shop\Category; use App\Models\Shop\Category;
use App\Repositories\Core\Tag; use App\Repositories\Core\Tag;
use App\Repositories\Core\Categories as CategoryTrees;
class Categories class Categories
{ {
@@ -19,8 +20,10 @@ class Categories
public static function getFull($id) public static function getFull($id)
{ {
$category = Category::with('CategoryTree')->find($id); $category = self::get($id);
$data = $category->toArray(); $data = $category->toArray();
$data['name'] = $category->name;
$data['description'] = $category->description;
$data['tags'] = self::getTagsByCategory($category); $data['tags'] = self::getTagsByCategory($category);
return $data; return $data;
} }
@@ -35,11 +38,6 @@ class Categories
return $category->tags->pluck('name', 'id')->toArray(); return $category->tags->pluck('name', 'id')->toArray();
} }
public static function getByCategory($category_id)
{
return Category::byCategory($category_id)->first();
}
public static function getTree() public static function getTree()
{ {
return CategoryTrees::getTree(); return CategoryTrees::getTree();
@@ -47,7 +45,7 @@ class Categories
public static function getOptions() public static function getOptions()
{ {
return Category::orderBy('name', 'asc')->pluck('name', 'category_id')->toArray(); return Category::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
} }
public static function storeFull($data) public static function storeFull($data)

View File

@@ -26,6 +26,14 @@ class Customers
return Customer::find($id); return Customer::find($id);
} }
public static function edit($id)
{
$customer = Customer::with(['addresses'])->find($id);
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
return $data;
}
public static function storeFull($data) public static function storeFull($data)
{ {
$deliveries = $data['deliveries']; $deliveries = $data['deliveries'];

View File

@@ -6,17 +6,42 @@ use App\Models\Shop\Offer;
class Offers class Offers
{ {
public static function getThumbSrcById($id)
{
return self::getThumbSrc(self::get($id));
}
public static function getThumbSrc(Offer $offer)
{
return Articles::getThumbSrc($offer->article->image);
}
public static function getLast() public static function getLast()
{ {
return Offer::with(['article.image'])->orderByDesc('updated_at')->get(); return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
} }
public static function getByCategoryWithTags($category_id)
{
$category = Categories::get($category_id);
$tags = Categories::getTagsByCategory($category);
$offers1 = self::getByCategory($category_id)->toArray();
$offers2 = self::getByTags($tags)->toArray();
$data = array_merge($offers1, $offers2);
return $data;
}
public static function getByCategory($category_id) public static function getByCategory($category_id)
{ {
return Offer::with(['article.image'])->byCategory($category_id)->get(); return Offer::with(['article.image'])->byCategory($category_id)->get();
} }
public static function getByTags($tags)
{
return Offer::with(['article.tags'])->byTags($tags)->get();
}
public static function getAll() public static function getAll()
{ {
return Offer::orderBy('value', 'asc')->get(); return Offer::orderBy('value', 'asc')->get();

View File

@@ -15,6 +15,16 @@ class Tags
return Tag::get()->pluck('name', 'id')->toArray(); return Tag::get()->pluck('name', 'id')->toArray();
} }
public static function getWithCountOffers()
{
return Tag::withCount(['offers'])->get()->toArray();
}
public static function getWithCountArticles()
{
return Tag::withCount(['articles'])->get()->toArray();
}
public static function getOptionsFullName() public static function getOptionsFullName()
{ {
$tags = Tag::with('group')->get(); $tags = Tag::with('group')->get();

View File

@@ -33,7 +33,7 @@ trait Imageable
public static function getPreviewSrc($image) public static function getPreviewSrc($image)
{ {
return Medias::getPreviewSrc($image); return $image ? Medias::getPreviewSrc($image) : null;
} }
public static function deleteImage($id, $index) public static function deleteImage($id, $index)

View File

@@ -8,12 +8,13 @@
], ],
"license": "proprietary", "license": "proprietary",
"require": { "require": {
"php": "^7.4", "php": "^7.4|^8.0",
"alexisgeneau/mailvalidate": "dev-master", "alexisgeneau/mailvalidate": "dev-master",
"arcanedev/log-viewer": "^8.1", "arcanedev/log-viewer": "^8.1",
"arrilot/laravel-widgets": "^3.13", "arrilot/laravel-widgets": "^3.13",
"barryvdh/laravel-dompdf": "^0.9", "barryvdh/laravel-dompdf": "^0.9",
"barryvdh/laravel-snappy": "^0.4.7", "barryvdh/laravel-snappy": "^0.4.7",
"bencoderus/min-auth": "^1.0",
"box/spout": "^3.3", "box/spout": "^3.3",
"browner12/helpers": "^3.0", "browner12/helpers": "^3.0",
"cesargb/laravel-cascade-delete": "^1.2", "cesargb/laravel-cascade-delete": "^1.2",

View File

@@ -17,7 +17,7 @@ return [
// Categories Models // Categories Models
'models' => [ 'models' => [
'category' => \Rinvex\Categories\Models\Category::class, 'category' => App\Models\Core\Category::class,
], ],
]; ];

View File

@@ -1,5 +1,5 @@
{ {
"name": "FGDigital", "name": "OpenSEM",
"version": "2.0.0", "version": "2.0.0",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@@ -20,7 +20,7 @@
@include('components.form.select', ['name' => 'deliveries[]', 'list' => $deliveries ?? [], 'values' => $customer['deliveries'] ?? null, 'with_empty' => '', 'class' => 'select2', 'multiple' => true]) @include('components.form.select', ['name' => 'deliveries[]', 'list' => $deliveries ?? [], 'values' => $customer['deliveries'] ?? null, 'with_empty' => '', 'class' => 'select2', 'multiple' => true])
</div> </div>
</div> </div>
@include('components.address', ['with_country' => false, 'prefix' => 'addresses[0]', 'with_tab' => true]) @include('components.address', ['with_country' => false, 'prefix' => 'addresses[0]', 'with_tab' => true, 'item' => $customer['addresses'][0]])
</div> </div>
</div> </div>

View File

@@ -1,5 +1,5 @@
<div class="card"> <div class="card">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image']) }}" class="card-img-top" alt="..."> <img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image'] ?? false) }}" class="card-img-top" alt="...">
<div class="card-body"> <div class="card-body">
<span class="card-title">{{ $offer['article']['name'] }}</span> <span class="card-title">{{ $offer['article']['name'] }}</span>
<span class="pull-right"> <span class="pull-right">

View File

@@ -1,6 +1,6 @@
<div class="row"> <div class="row">
@foreach ($offers as $offer) @foreach ($offers as $offer)
<div class="col-sm-6 col-md-3 col-lg-2"> <div class="col-sm-3 col-lg-2">
@include('Shop.layout.partials.article') @include('Shop.layout.partials.article')
</div> </div>
@endforeach @endforeach

View File

@@ -0,0 +1,3 @@
<div class="w-100 h-100 bg-secondary">
Filtres
</div>

View File

@@ -4,17 +4,19 @@
@section('content') @section('content')
<div class="row"> <div class="row">
<div class="col-8"> <div class="col-3 col-lg-2">
<h1 style="font-size: 2em;">{{ $category['name'] }}</h1> @include('Shop.layout.partials.category_filters')
<h3 style="font-size: 1.2em;">{!! $category['description'] !!}</h3>
</div> </div>
<div class="col-4"> <div class="col-9 col-lg-10">
@include('Shop.layout.partials.category_add') <div class="row">
</div> <div class="col-8">
</div> <h1 style="font-size: 2em;">{{ $category['name'] }}</h1>
<h3 style="font-size: 1.2em;">{!! $category['description'] !!}</h3>
<div class="row"> </div>
<div class="col-12"> <div class="col-4">
@include('Shop.layout.partials.category_add')
</div>
</div>
@include('Shop.layout.partials.category_articles') @include('Shop.layout.partials.category_articles')
</div> </div>
</div> </div>

View File

@@ -25,32 +25,32 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12 col-lg-6 form-group"> <div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}address">{{ __('street') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}address">{{ __('street') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address]' : 'address'), 'value' => $item[($prefix ?? null) . 'address'] ?? null, 'disabled' => $disabled ?? false ]) @include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address]' : 'address'), 'value' => ($with_tab ?? false) ? $item['address'] : ($item[($prefix ?? null) . 'address'] ?? null), 'disabled' => $disabled ?? false ])
</div> </div>
<div class="col-12 col-lg-6 form-group"> <div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}address2">{{ __('street_complement') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}address2">{{ __('street_complement') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address2]' : 'address2'), 'value' => $item[($prefix ?? null) . 'address2'] ?? null, 'disabled' => $disabled ?? false ]) @include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[address2]' : 'address2'), 'value' => ($with_tab ?? false) ? $item['address2'] : ($item[($prefix ?? null) . 'address2'] ?? null), 'disabled' => $disabled ?? false ])
</div> </div>
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-6 form-group"> <div class="col-6 form-group">
<label class="light" for="{{ $prefix ?? null }}zipcode">{{ __('zipcode') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}zipcode">{{ __('zipcode') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[zipcode]' : 'zipcode'), 'value' => $item[($prefix ?? null) . 'zipcode'] ?? null, 'disabled' => $disabled ?? false ]) @include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[zipcode]' : 'zipcode'), 'value' => ($with_tab ?? false) ? $item['zipcode'] : ($item[($prefix ?? null) . 'zipcode'] ?? null), 'disabled' => $disabled ?? false ])
</div> </div>
<div class="col-6 form-group"> <div class="col-6 form-group">
<label class="light" for="{{ $prefix ?? null }}city">{{ __('city') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}city">{{ __('city') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[city]' : 'city'), 'value' => $item[($prefix ?? null) . 'city'] ?? null, 'disabled' => $disabled ?? false ]) @include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[city]' : 'city'), 'value' => ($with_tab ?? false) ? $item['city'] : ($item[($prefix ?? null) . 'city'] ?? null), 'disabled' => $disabled ?? false ])
</div> </div>
</div> </div>
@if ($with_country ?? true) @if ($with_country ?? true)
<div class="row mb-3"> <div class="row mb-3">
<div class="col-12 col-lg-6 form-group"> <div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}country">{{ __('country') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}country">{{ __('country') }}</label><br/>
@include('components.form.select', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[country_id]' : 'country_id'), 'list' => $countries ?? null, 'value' => $item[($prefix ?? null) . 'country_id'] ?? null, 'with_empty' => '', 'required' => true, 'disabled' => $disabled ?? false ]) @include('components.form.select', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[country_id]' : 'country_id'), 'list' => $countries ?? null, 'value' => ($with_tab ?? false) ? $item['country_id'] : ($item[($prefix ?? null) . 'country_id'] ?? null), 'with_empty' => '', 'required' => true, 'disabled' => $disabled ?? false ])
</div> </div>
<div class="col-12 col-lg-6 form-group"> <div class="col-12 col-lg-6 form-group">
<label class="light" for="{{ $prefix ?? null }}state">{{ __('state') }}</label><br/> <label class="light" for="{{ $prefix ?? null }}state">{{ __('state') }}</label><br/>
@include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[state]' : 'state'), 'value' => $item[($prefix ?? null) . 'state'] ?? null, 'disabled' => $disabled ?? false ]) @include('components.form.input', ['name' => ($prefix ?? null) . (($with_tab ?? false) ? '[state]' : 'state'), 'value' => ($with_tab ?? false) ? $item['state'] : ($item[($prefix ?? null) . 'state'] ?? null), 'disabled' => $disabled ?? false ])
</div> </div>
</div> </div>
@endif @endif

View File

@@ -1,4 +1,16 @@
<input type="hidden" name="{{ $name ?? ''}}" value="0"> <input type="checkbox" name="{{ $name ?? ''}}" id="{{ $id_name ?? $name ?? '' }}"
<input type="checkbox" name="{{ $name ?? ''}}" id="{{ $id_name ?? $name ?? '' }}" class="{{ $class ?? 'toggle'}}" value="{{ $val ?? 1}}" data-toggle="toggle" data-on="{{ $on ?? __('yes') }}" data-off="{{ $off ?? __('no') }}" data-onstyle="{{ $onstyle ?? 'outline-success'}}" data-offstyle="{{ $offstyle ?? 'outline-danger'}}" data-size="{{ $size ?? '' }}" @if ( (isset($value) && isset($val) && ($value == $val)) || (!isset($val) && isset($value) && $value)) checked @endif {{ $disabled ?? ''}} {{ $meta ?? ''}} > class="{{ $class ?? 'toggle'}}"
value="{{ $val ?? 1}}"
data-name="{{ $id_name ?? $name ?? '' }}"
data-toggle="toggle"
data-on="{{ $on ?? __('yes') }}"
data-off="{{ $off ?? __('no') }}"
data-onstyle="{{ $onstyle ?? 'outline-success'}}"
data-offstyle="{{ $offstyle ?? 'outline-danger'}}"
data-size="{{ $size ?? '' }}"
@if ( (isset($value) && isset($val) && ($value == $val)) || (!isset($val) && isset($value) && $value)) checked @endif
@if (isset($disabled) && $disabled) disabled="disabled" @endif
{{ $meta ?? ''}}
>
@include('load.form.toggle') @include('load.form.toggle')

View File

@@ -12,7 +12,8 @@
$('input' + selector).change(function() { $('input' + selector).change(function() {
data['id'] = $(this).data('id'); data['id'] = $(this).data('id');
data['active'] = $(this).is(':checked'); var name = (typeof($(this).data('name')) == 'undefined') ? 'active' : $(this).data('name');
data[name] = $(this).is(':checked');
if (data['id'] && (typeof(url) != 'undefined') && (url != '')) { if (data['id'] && (typeof(url) != 'undefined') && (url != '')) {
var dataJson = Object.assign({}, data); var dataJson = Object.assign({}, data);
$.post(url, dataJson); $.post(url, dataJson);