Quantcast
Viewing latest article 20
Browse Latest Browse All 30

web.php

web.php
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Spatie\YamlFrontMatter\YamlFrontMatter;
Route::get('{slug?}', function ($slug = 'index') {
$path = resource_path('pages/' . $slug . '.md');
if (!file_exists($path)) {
abort(404);
}
$data = cache()->remember($slug . filemtime($path), 60 * 60, function() use ($path) {
$raw = file_get_contents($path);
$object = YamlFrontMatter::parse($raw);
return [
'title' => $object->matter('title'),
'body' => Str::markdown($object->body()),
];
});
return view('page', $data);
})->where('slug', '.*');

Viewing latest article 20
Browse Latest Browse All 30

Trending Articles