Created
February 3, 2024 23:14
-
-
Save captenmasin/f81cb1a7354e7cf0ade6e82541718278 to your computer and use it in GitHub Desktop.
Nice simple content management for "generic" pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Cache; | |
use Illuminate\Support\Str; | |
use Symfony\Component\Yaml\Yaml; | |
class GenericPageController | |
{ | |
public function __invoke() | |
{ | |
$file = request()->path(); | |
$filePath = resource_path().'/content/'.$file.'.yaml'; | |
if (!file_exists($filePath)) { | |
abort(404); | |
} | |
[$parsedFile, $content] = Cache::rememberForever('page:'.$file, function () use ($filePath) { | |
$parsedFile = Yaml::parse(file_get_contents($filePath)); | |
$content = Str::markdown($parsedFile['content']); | |
return [$parsedFile, $content]; | |
}); | |
return view('generic', [ | |
'title' => $parsedFile['title'] ?? '', | |
'description' => $parsedFile['description'] ?? null, | |
'date' => $parsedFile['date'] ?? null, | |
'content' => $content ?? '', | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title: "Terms & Conditions" | |
date: "2024-02-03" | |
content: | | |
# Lorem ipsum! | |
This is a **Markdown** example. | |
## Here's a list: | |
- Item 1 | |
- Item 2 | |
- Item 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
Route::get('terms', GenericPageController::class); | |
Route::get('privacy', GenericPageController::class); | |
Route::get('etc-etc', GenericPageController::class); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment