Laravel 8 From Scratch: Episode 10
<?php | |
use Illuminate\Support\Facades\Route; | |
/* | |
|-------------------------------------------------------------------------- | |
| Web Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register web routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| contains the "web" middleware group. Now create something great! | |
| | |
*/ | |
Route::get('/', function () { | |
return view('posts'); | |
}); | |
Route::get('posts/{post}', function ($slug) { | |
if (! file_exists($path = __DIR__ . "/../resources/posts/{$slug}.html")) { | |
return redirect('/'); | |
} | |
$post = cache()->remember("posts.{$slug}", 1200, fn() => file_get_contents($path)); | |
return view('post', ['post' => $post]); | |
})->where('post', '[A-z_\-]+'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment