Skip to content

Instantly share code, notes, and snippets.

@Rndwiga
Forked from marktopper/PageController.php
Created March 22, 2017 11:30
Show Gist options
  • Save Rndwiga/ca7e0b460c2384da0b60d6c680ace9ff to your computer and use it in GitHub Desktop.
Save Rndwiga/ca7e0b460c2384da0b60d6c680ace9ff to your computer and use it in GitHub Desktop.
[Voyager] Routes for Pages BREAD
<?php
class PageController extends \App\Http\Controllers\Controller
{
public function show()
{
$slug = request()->segment(1);
$page = \TCG\Voyager\Models\Page::where('slug', $slug)
->firstOrFail();
return view('show-page', [
'page' => $page,
]);
}
}
<?php
try {
$pages = \TCG\Voyager\Models\Page::all();
foreach ($pages as $page) {
Route::get($page->slug, 'PageController@show');
}
} catch (\Exception $exception) {
// do nothing
}
<h1>{{ $page->title }}</h1>
<?php echo $page->body; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment