45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
// use Rinvex\Categories\Traits\Categorizable;
|
|
use Rinvex\Tags\Traits\Taggable;
|
|
use Wildside\Userstamps\Userstamps;
|
|
|
|
class Category extends Model
|
|
{
|
|
use HasTranslations, InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
|
|
|
|
protected $guarded = ['id'];
|
|
protected $table = 'categories';
|
|
public $translatable = ['name','description'];
|
|
|
|
public function Articles()
|
|
{
|
|
return $this->morphedByMany(Article::class, 'categorizable');
|
|
}
|
|
|
|
public function ArticlesTagged()
|
|
{
|
|
return $this->tags->articles;
|
|
}
|
|
|
|
public function countArticlesTagged()
|
|
{
|
|
return $this->tags()->withCount('Articles');
|
|
}
|
|
|
|
public function scopeByCategory($query, $category_id)
|
|
{
|
|
return $query->where('category_id', $category_id);
|
|
}
|
|
}
|