Initial Commit
This commit is contained in:
31
app/Models/Category.php
Normal file
31
app/Models/Category.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Sluggable;
|
||||
|
||||
protected $fillable = ["name","slug", "parent", "ordering"];
|
||||
|
||||
public function sluggable(): array {
|
||||
return [
|
||||
"slug" => [
|
||||
'source' => 'name'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function parent_category() {
|
||||
return $this->belongsTo(ParentCategory::class, 'parent', 'id');
|
||||
}
|
||||
|
||||
public function posts() {
|
||||
return $this->hasMany(Post::class, 'category', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user