- Created NewsResource for managing news entries. - Added pages for creating, editing, and listing news. - Defined NewsForm schema for news entry forms. - Configured NewsTable for displaying news records with actions. - Implemented News model with relationships and soft deletes. - Added factories for generating test data for news and tags. - Created migrations for news and tags tables.
33 lines
835 B
PHP
33 lines
835 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
use Spatie\Sluggable\HasSlug;
|
|
use Spatie\Sluggable\SlugOptions;
|
|
use Spatie\Tags\HasTags;
|
|
|
|
class News extends Model implements HasMedia
|
|
{
|
|
use HasFactory, HasSlug, HasTags, InteractsWithMedia, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
public function getSlugOptions(): SlugOptions
|
|
{
|
|
return SlugOptions::create()
|
|
->generateSlugsFrom('title')
|
|
->saveSlugsTo('slug');
|
|
}
|
|
|
|
public function author(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'author_id');
|
|
}
|
|
}
|