2024-02-05 02:36:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2025-10-07 03:10:25 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2024-08-04 17:32:32 +00:00
|
|
|
use Illuminate\Support\Str;
|
2024-02-05 02:36:25 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2025-10-07 03:10:25 +00:00
|
|
|
use Illuminate\Support\Carbon;
|
2024-02-05 02:36:25 +00:00
|
|
|
|
|
|
|
|
class Article extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
/** The name of the database table storing this Model's records. */
|
2024-08-04 04:49:42 +00:00
|
|
|
protected $table = 'articles';
|
2024-02-05 02:36:25 +00:00
|
|
|
|
|
|
|
|
/** The attributes on the Model that can be mass-assigned */
|
2024-08-04 04:49:42 +00:00
|
|
|
protected $fillable = [
|
2024-02-05 02:36:25 +00:00
|
|
|
'title',
|
|
|
|
|
'subtitle',
|
|
|
|
|
'author_id',
|
|
|
|
|
'slug',
|
|
|
|
|
'body',
|
|
|
|
|
'published_at',
|
|
|
|
|
'header_image_url',
|
2024-08-04 17:32:32 +00:00
|
|
|
'markdown_body',
|
2024-02-05 02:36:25 +00:00
|
|
|
'processed_at',
|
|
|
|
|
];
|
|
|
|
|
|
2025-10-07 03:10:25 +00:00
|
|
|
/** ---------------------------------------
|
|
|
|
|
* ACCESSORS
|
|
|
|
|
* ---------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
protected function publishedAt(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: fn (string $value) => Carbon::parse($value)->format('D, M jS o, g:i A'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** ---------------------------------------
|
|
|
|
|
* RELATIONSHIPS
|
|
|
|
|
* ---------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2024-02-05 02:36:25 +00:00
|
|
|
/** The person that wrote the article. */
|
|
|
|
|
public function author(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Author::class);
|
|
|
|
|
}
|
2024-08-04 17:32:32 +00:00
|
|
|
|
2025-10-07 03:10:25 +00:00
|
|
|
/** ---------------------------------------
|
|
|
|
|
* MODEL METHODS
|
|
|
|
|
* ---------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2024-08-04 17:32:32 +00:00
|
|
|
public function convertMarkdownToMarkup()
|
|
|
|
|
{
|
2025-03-23 23:12:42 +00:00
|
|
|
if (is_null($this->markdown_body)) return null;
|
|
|
|
|
|
2024-08-04 17:32:32 +00:00
|
|
|
$this->body = Str::of($this->markdown_body)->markdown([
|
|
|
|
|
'html_input' => 'strip',
|
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2024-02-05 02:36:25 +00:00
|
|
|
}
|