dym-sh/app/Models/Article.php

27 lines
487 B
PHP
Raw Normal View History

2024-08-09 10:37:35 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
2024-08-09 13:52:23 +02:00
class Article extends Model
2024-08-09 10:37:35 +02:00
{
2024-08-09 13:52:23 +02:00
protected $table = 'articles';
2024-08-09 10:37:35 +02:00
2024-08-09 13:52:23 +02:00
use HasFactory;
2024-08-09 10:37:35 +02:00
public static function find(string $slug): array
{
$article = Arr::first(Article::all(), fn($article) => $article['slug'] === $slug);
if(! $article ) {
abort(404);
}
return $article;
}
}