📅  最后修改于: 2022-03-11 14:54:35.536000             🧑  作者: Mango
rememberForever('posts.all', function () {
return collect(File::files(resource_path('posts')))
->map(fn ($file) => YamlFrontMatter::parseFile($file))
->map(fn ($doc) => new Post(
$doc->title,
$doc->excerpt,
$doc->date,
$doc->body(),
$doc->slug
))
->sortByDesc('date');
});
}
public static function find($slug)
{
return static::all()->firstWhere('slug', $slug);
}
public static function findOrFail($slug)
{
$post = static::find($slug);
if (! $post) {
throw new ModelNotFoundException();
}
return $post;
}
}