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!
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
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community