Last active
December 24, 2020 20:55
-
-
Save marktopper/ad3f8048a1a7bf55a5fcc747745d92ec to your computer and use it in GitHub Desktop.
[Voyager] Routes for Pages BREAD
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 | |
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, | |
]); | |
} | |
} |
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 | |
try { | |
$pages = \TCG\Voyager\Models\Page::all(); | |
foreach ($pages as $page) { | |
Route::get($page->slug, 'PageController@show'); | |
} | |
} catch (\Exception $exception) { | |
// do nothing | |
} |
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
<h1>{{ $page->title }}</h1> | |
<?php echo $page->body; ?> |
Ahh thanks for clearing that our @redsoxfan2499 👍
I have updated the gist.
sorry for my stupid question, maybe you can give a cue me how to display post from voyager ( e.g. that post that I got from "php artisan voyager:install --with-dummy" command, how to get them in my view.
Thanks Mark - worked for me too. This stuff really needs to be added to the official docs!
How about :
Route::get('/pages/{slug}', 'PagesController@getPage'); <-- web.php
public function getPage($slug)
{
$page = DB::table('pages')->where('slug', $slug)->firstOrFail();
return view('pages/index', ['page' => $page]);
}
Hi @marktopper how to modification Post admin page , I will install or add module tags in post add,
btw I uses : https://cartalyst.com/manual/tags/4.0#adding-tags
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Mark. The above code did not work out of the box. I kept getting errors and noticed that in the Page Controller, the $slug was always null. So after some testing, I changed the following line
$slug = request()->segment(0);
to
$slug = request()->segment(1);
and now works:
Thanks for making the Voyager system.