23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* App\Models\Category
|
||||
|
|
@ -49,26 +50,21 @@ use Cviebrock\EloquentSluggable\Sluggable;
|
|||
* @property-read int|null $translations_count
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use Sluggable;
|
||||
|
||||
protected $table = 'categories';
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'parent_id', 'name', 'headline', 'pos', 'active',
|
||||
'parent_id',
|
||||
'name',
|
||||
'headline',
|
||||
'pos',
|
||||
'active',
|
||||
'slug',
|
||||
];
|
||||
|
||||
public function sluggable() : array
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'name'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Category', 'parent_id');
|
||||
|
|
@ -82,48 +78,50 @@ class Category extends Model
|
|||
public function product_categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id')->orderBy('pos', 'DESC');
|
||||
|
||||
}
|
||||
|
||||
public function productCategoriesCountActive()
|
||||
{
|
||||
$category_id = $this->id;
|
||||
return Product::where('active', true)->whereHas('product_categories', function ($query) use ($category_id) {
|
||||
$query->where('category_id', $category_id); //
|
||||
})->orderBy('pos', 'ASC')->count();
|
||||
$query->where('category_id', $category_id); //
|
||||
})->orderBy('pos', 'ASC')->count();
|
||||
}
|
||||
|
||||
public function productCategoriesCountActiveOn($show_on = ['1'])
|
||||
{
|
||||
$category_id = $this->id;
|
||||
return Product::where('active', true)->whereJsonContains('show_on', $show_on)
|
||||
->whereHas('product_categories', function ($query) use ($category_id) {
|
||||
$query->where('category_id', $category_id); //
|
||||
})->orderBy('pos', 'ASC')->count();
|
||||
->whereHas('product_categories', function ($query) use ($category_id) {
|
||||
$query->where('category_id', $category_id); //
|
||||
})->orderBy('pos', 'ASC')->count();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function setSlugAttribute($value)
|
||||
{
|
||||
$slug = Str::slug($value);
|
||||
if (self::where('slug', $slug)->exists()) {
|
||||
$slug = $slug . '-' . self::where('slug', $slug)->count();
|
||||
}
|
||||
$this->attributes['slug'] = $slug;
|
||||
}
|
||||
|
||||
public function iq_image()
|
||||
{
|
||||
return $this->belongsTo('App\Models\IqImage', 'headline_image_id');
|
||||
}
|
||||
|
||||
public function setPosAttribute($value){
|
||||
public function setPosAttribute($value)
|
||||
{
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(TransCategory::class, 'categorie_id');
|
||||
}
|
||||
|
||||
|
||||
public function getLang($key)
|
||||
public function getLang($key)
|
||||
{
|
||||
$lang = \App::getLocale();
|
||||
if ($lang == 'de') {
|
||||
|
|
@ -135,9 +133,7 @@ class Category extends Model
|
|||
|
||||
public function getTrans($key, $lang)
|
||||
{
|
||||
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
|
||||
$trans = $this->translations->where('language', '=', $lang)->where('key', $key)->first();
|
||||
return $trans ? $trans->value : '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue