82 lines
1.7 KiB
PHP
82 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kalnoy\Nestedset\NodeTrait;
|
|
use Pgvector\Laravel\HasNeighbors;
|
|
use Pgvector\Laravel\Vector;
|
|
use Spatie\Tags\HasTags;
|
|
|
|
/**
|
|
* Class Category
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $slug
|
|
* @property string $description
|
|
* @property int $_lft
|
|
* @property int $_rgt
|
|
* @property int|null $parent_id
|
|
* @property string|null $subcategories
|
|
* @property string|null $meme_angles
|
|
* @property string|null $sample_captions
|
|
* @property string|null $keywords
|
|
* @property string $payload
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*/
|
|
class Category extends Model
|
|
{
|
|
use HasNeighbors, HasTags, NodeTrait;
|
|
|
|
protected $table = 'categories';
|
|
|
|
protected $casts = [
|
|
'embedding' => Vector::class,
|
|
'_lft' => 'int',
|
|
'_rgt' => 'int',
|
|
'parent_id' => 'int',
|
|
'subcategories' => 'object',
|
|
'meme_angles' => 'array',
|
|
'sample_captions' => 'array',
|
|
'keywords' => 'array',
|
|
'payload' => 'object',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
'description',
|
|
'_lft',
|
|
'_rgt',
|
|
'parent_id',
|
|
'subcategories',
|
|
'meme_angles',
|
|
'sample_captions',
|
|
'keywords',
|
|
'payload',
|
|
];
|
|
|
|
/**
|
|
* Scope to get only main categories
|
|
*/
|
|
public function scopeMainCategories($query)
|
|
{
|
|
return $query->whereNull('parent_id');
|
|
}
|
|
|
|
/**
|
|
* Scope to get only subcategories
|
|
*/
|
|
public function scopeSubcategories($query)
|
|
{
|
|
return $query->whereNotNull('parent_id');
|
|
}
|
|
}
|