Add Page resource to Filament admin panel: Implemented Page model, resource, and associated pages (create, edit, list). Defined page form schema and table configuration. Added migration for pages table.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'content',
|
||||
'excerpt',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'status',
|
||||
'featured_image',
|
||||
'published_at',
|
||||
'author_id',
|
||||
'parent_id',
|
||||
'sort_order',
|
||||
'template',
|
||||
'is_homepage',
|
||||
'show_in_menu',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'published_at' => 'datetime',
|
||||
'is_homepage' => 'boolean',
|
||||
'show_in_menu' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'author_id');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Page::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Page::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
public function getUrlAttribute()
|
||||
{
|
||||
if ($this->is_homepage) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return '/' . $this->slug;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user