add validator, optimizations
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user