word-salad/app/Models/Article.php

44 lines
1022 B
PHP

<?php
namespace App\Models;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Article extends Model
{
use HasFactory;
/** The name of the database table storing this Model's records. */
protected $table = 'articles';
/** The attributes on the Model that can be mass-assigned */
protected $fillable = [
'title',
'subtitle',
'author_id',
'slug',
'body',
'published_at',
'header_image_url',
'markdown_body',
'processed_at',
];
/** The person that wrote the article. */
public function author(): BelongsTo
{
return $this->belongsTo(Author::class);
}
public function convertMarkdownToMarkup()
{
$this->body = Str::of($this->markdown_body)->markdown([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
}
}