add validator, optimizations
This commit is contained in:
@@ -12,7 +12,7 @@ class ArticlesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'articles';
|
||||
|
||||
public $sortedColumn = 2;
|
||||
public $sortedColumn = 3;
|
||||
|
||||
public function query(Article $model)
|
||||
{
|
||||
@@ -99,15 +99,16 @@ class ArticlesDataTable extends DataTable
|
||||
return [
|
||||
Column::make('visible')->title('Visible')->searchable(false)->width(50),
|
||||
Column::make('homepage')->title('Accueil')->searchable(false)->width(50),
|
||||
Column::make('ref')->title('Ref'),
|
||||
Column::make('article_nature.name')->title('Nature'),
|
||||
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
|
||||
Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false)->width(40),
|
||||
// Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
|
||||
// Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('categories_count')->title('#Ray')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('offers_count')->title('#Ofr')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('images_count2')->title('#PhoH')->class('text-right')->searchable(false)->orderable(false)->width(40),
|
||||
// Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false)->width(40),
|
||||
// Column::make('images_count2')->title('#PhoH')->class('text-right')->searchable(false)->orderable(false)->width(40),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\Datatables\Admin\Shop\ArticlesDataTable;
|
||||
use App\Http\Requests\Admin\Shop\StoreArticlePost;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\Categories;
|
||||
@@ -20,9 +21,11 @@ class ArticleController extends Controller
|
||||
|
||||
public function index(ArticlesDataTable $dataTable)
|
||||
{
|
||||
$data['article_natures'] = ArticleNatures::getOptions();
|
||||
$data['categories'] = Categories::getOptions();
|
||||
$data['tags'] = Tags::getOptionsFullName();
|
||||
$data = [
|
||||
'article_natures' => ArticleNatures::getOptions(),
|
||||
'categories' => Categories::getOptions(),
|
||||
'tags' => Tags::getOptionsFullName(),
|
||||
];
|
||||
|
||||
return $dataTable->render('Admin.Shop.Articles.list', $data);
|
||||
}
|
||||
@@ -34,9 +37,12 @@ class ArticleController extends Controller
|
||||
return view('Admin.Shop.Articles.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(StoreArticlePost $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['visible'] = $data['visible'] ?? false;
|
||||
$data['homepage'] = $data['homepage'] ?? false;
|
||||
|
||||
Articles::storeFull($data);
|
||||
|
||||
return redirect()->route('Admin.Shop.Articles.index');
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\Datatables\Admin\Shop\OffersDataTable;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\Shop\StoreOfferPost;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\Offers;
|
||||
@@ -16,32 +17,30 @@ class OfferController extends Controller
|
||||
{
|
||||
public function index(OffersDataTable $dataTable)
|
||||
{
|
||||
$data['article_natures'] = ArticleNatures::getOptions();
|
||||
$data['packages'] = Packages::getOptions();
|
||||
$data = [
|
||||
'article_natures' => ArticleNatures::getOptions(),
|
||||
'packages' => Packages::getOptions(),
|
||||
];
|
||||
|
||||
return $dataTable->render('Admin.Shop.Offers.list', $data ?? []);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['articles'] = Articles::getOptionsWithNature();
|
||||
$data['tariffs'] = Tariffs::getOptions();
|
||||
$data['variations'] = Variations::getOptions();
|
||||
$data = Offers::init();
|
||||
|
||||
return view('Admin.Shop.Offers.create', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['offer'] = Offers::get($id)->toArray();
|
||||
$data['articles'] = Articles::getOptionsWithNature();
|
||||
$data['tariffs'] = Tariffs::getOptions();
|
||||
$data['variations'] = Variations::getOptions();
|
||||
$data = Offers::init();
|
||||
$data['offer'] = Offers::getArray($id);
|
||||
|
||||
return view('Admin.Shop.Offers.edit', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(StoreOfferPost $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$ret = Offers::store($data);
|
||||
@@ -51,7 +50,7 @@ class OfferController extends Controller
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data['offer'] = Offers::get($id)->toArray();
|
||||
$data['offer'] = Offers::getArray($id);
|
||||
|
||||
return view('Admin.Shop.Offers.view', $data);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@ class StoreArticlePost extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'ref' => 'required|unique:articles,ref,'.$this->ref,
|
||||
'ref' => 'required|unique:shop_articles,ref,'.$this->id,
|
||||
'product_type' => 'required',
|
||||
'product_id' => 'required',
|
||||
'article_nature_id' => 'required',
|
||||
'name' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
23
app/Http/Requests/Admin/Shop/StoreOfferPost.php
Normal file
23
app/Http/Requests/Admin/Shop/StoreOfferPost.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Shop;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreOfferPost extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'article_id' => 'required',
|
||||
'variation_id' => 'required',
|
||||
'tariff_id' => 'required',
|
||||
'weight' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
@@ -13,7 +14,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
class Articles
|
||||
{
|
||||
use Imageable;
|
||||
use Basic, Imageable;
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
@@ -73,11 +74,6 @@ class Articles
|
||||
return Offers::getOffersByArticle($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Article::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsWithNature()
|
||||
{
|
||||
$articles = Article::with(['article_nature'])->get();
|
||||
@@ -391,17 +387,17 @@ class Articles
|
||||
{
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data['images'] = Varieties::getImages($product_id);
|
||||
$images = Varieties::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data['images'] = Species::getImages($product_id);
|
||||
$images = Species::getImages($product_id);
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data['images'] = Merchandises::getImages($product_id);
|
||||
$images = Merchandises::getImages($product_id);
|
||||
break;
|
||||
}
|
||||
|
||||
return $data ?? false;
|
||||
return $images ?? false ? ['images' => $images] : false;
|
||||
}
|
||||
|
||||
public static function getMeta(&$data = [])
|
||||
@@ -516,11 +512,6 @@ class Articles
|
||||
return Prices::getByArticle($article->id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getFullImagesByArticleId($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
@@ -611,32 +602,6 @@ class Articles
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$data['visible'] = $data['visible'] ?? false;
|
||||
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Article::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = self::get($id);
|
||||
$ret = $article->update($data);
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Article::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if (! $categories) {
|
||||
@@ -677,4 +642,9 @@ class Articles
|
||||
|
||||
return $name ? hash('crc32c', Str::slug($name)) : false;
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Article::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,19 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function count()
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return Offer::count();
|
||||
return [
|
||||
'articles' => Articles::getOptionsWithNature(),
|
||||
'tariffs' => Tariffs::getOptions(),
|
||||
'variations' => Variations::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getWeight($id, $quantity = 1)
|
||||
@@ -116,42 +123,13 @@ class Offers
|
||||
return Offer::with(['article.tags'])->byTags($tags)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Offer::get();
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? Offer::with($relations)->findOrFail($id) : Offer::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Offer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Offer::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $status_id)
|
||||
{
|
||||
return self::update(['status_id' => $status_id], $id);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Offer::query();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user