i have created a dynamic link and displayed it on front end but i don,t know how to create a slug or route for it through laravel voyager without going to code and then how to display a page according to that menu where we have to put the link for the page in the menu so that when we click on that menu item so it goes to that page kindly give me step by step instruction for it
Hello, I know what you mean, but we haven't come up with a solution yet.
The same applies to Posts, or any other section using slugs.
can you not just create a page (when creating a menu) and vice versa automatically? Reference the page id with the menu and then add a route eg Route::get('{any}', 'PageController@index')->name('page'); and grab the page content in your model using the slug? That's how i'm doing it unless you know of a better solution?
I have no idea what's going on in this issue, and it's really old, so I'm going to close it.
Voyager is NOT a CMS, and will not create the pages for you. We do, however, provide you a very rudimentary method for displaying a menu. Everything else will function like a normal Laravel app.
You can make some like this
php artisan make:controller PagesController
app/Http/Controllers/PagesController.php must look like this:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use TCG\Voyager\Models\Page;
class PagesController extends Controller
{
// https://stackoverflow.com/questions/33003097/dynamic-routing-in-laravel-5-application
public function index()
{
$page = Page::where('slug', '/')->where('active', 1)->first();
return view('page')->with('page', $page);
}
public function getPage($slug = null)
{
$page = Page::where('slug', $slug)->where('status', 'active');
$page = $page->firstOrFail();
// return view($page->template)->with('page', $page);
return view('page')->with('page', $page);
}
}
create view resources/views/page.blade.php
@extends('layouts.app')
@section('content')
<div class="container pt-5" style="padding-top: 5rem !important;">
<h1>
{{ $page->title }}
</h1>
<div class="page-content__wrap">
{!! $page->body !!}
</div>
</div>
@endsection
add to end of route routes/web.php
...
// Catch all page controller (place at the very bottom)
Route::get('{slug}', [
'uses' => 'PagesController@getPage'
])->where('slug', '([A-Za-z0-9\-\/]+)');
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
You can make some like this
app/Http/Controllers/PagesController.php must look like this:
create view resources/views/page.blade.php
add to end of route routes/web.php