42 lines
985 B
PHP
42 lines
985 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class SubCategory extends Model
|
|
{
|
|
protected $table = 'sub_categories';
|
|
|
|
protected $fillable = ['category_id', 'name', 'description', 'is_deeplink_only'];
|
|
|
|
protected $casts = [
|
|
'is_deeplink_only' => 'boolean',
|
|
];
|
|
|
|
protected $appends = ['deep_link'];
|
|
|
|
public function getDeepLinkAttribute(): ?string
|
|
{
|
|
$canonical = config('deeplinks.subcategory_pattern');
|
|
|
|
if ($canonical) {
|
|
return rtrim(str_replace('{id}', $this->id, $canonical), '/');
|
|
}
|
|
|
|
return url('/subcategory/' . $this->id);
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function media(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Media::class, 'media_sub_category');
|
|
}
|
|
}
|