/
var
/
www
/
html
/
gnet_live
/
app
/
Models
/
Upload File
HOME
<?php namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Spatie\Sitemap\Contracts\Sitemapable; use Spatie\Sitemap\Tags\Url; class Article extends Model implements Sitemapable { use HasFactory; protected $table = 'artikel'; protected $fillable = [ 'title', 'url', 'author', 'date', 'banner_image', 'banner_image_low', 'banner_image_mobile', 'banner_image_mobile_low', 'alt_text', 'content', 'keywords', 'article_category_id' ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; public function generateTableOfContent() { $pattern = '/<h[1-6]>(.*?)<\/h[1-6]>/'; preg_match_all($pattern, $this->content, $matches); $toc = []; foreach ($matches[1] as $match) { $toc[] = $match; } return $toc; } public function article_category() { return $this->belongsTo(ArticleCategory::class, 'article_category_id'); } public function toSitemapTag(): Url|string|array { return Url::create(route('blog.show', $this->url)) ->setLastModificationDate(Carbon::create($this->updated_at)) ->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY) ->setPriority(0.1); } }