Voyager: how to create the menu and then pages according to that menu in the laravel voyager

Created on 20 Apr 2017  路  5Comments  路  Source: the-control-group/voyager

  • Laravel Version: #.#.#
  • Voyager Version: #.#.#
  • PHP Version:
  • Database Driver & Version:

Description:

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

Steps To Reproduce:

feature

Most helpful comment

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\-\/]+)');

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IvanBohonosiuk picture IvanBohonosiuk  路  4Comments

iwasherefirst2 picture iwasherefirst2  路  3Comments

TPRAsh picture TPRAsh  路  3Comments

rayqiri picture rayqiri  路  3Comments

MikadoInfo picture MikadoInfo  路  3Comments