Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 2 years ago.
0

Ok, I might have a solution. I could put my page controller at the bottom of my router.php, if the URL can not match any of other route path, so Laravel 4 know it might be a page route.

Route::get('{page}', array('uses' => 'pageController@getPage');

Any other better solutions? Thanks!

Last updated 2 years ago.
0

hetnieuweweb said:

Don't forget to place the '/' before your url.

Like this:

Route::get('/about-us', array('uses' => 'pageController@aboutUs');

When you make a lot of pages, you have to write every route...

That is actually wrong, you don't need the '/' all, unless the page is info/about-us

Last updated 2 years ago.
0

It would be better if you could make it as dynamic and fetch the data from the database.

So you can create this route

Route

Route::get('{slug}', array('as' => 'pages.show', 'uses' => 'PagesController@show'));

Controller

public function show($slug) {

$modulePage = Module::where('slug', $slug)->get(array('module_name', 'module_content'))->first();

return View::make('modulepages', compact('modulePage')); }

And then show the content to your View

<h3 class="page-header">{{$modulePage->module_name}}</h3> <p>{{$modulePage->module_content}}</p>

Hope this helps.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dd123123 dd123123 Joined 23 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.