Hi,
As I said in another post I'm trying to do my own CMS. I have several articles in my db, each article has his url alis (slug) defined
Currently in routes I do:
$contents = Content::all();
$hc = new HomeController;
foreach ($contents as $content) {
Route::get($content->slug, function () use ($content, $hc) {
return View::make('content')
->with('content', $content)
->with('menu', $hc->menu)
->with('isHome', false);
});
}
it works but is there a better / cleaner way to handle this?
Finally I found the solution below as a less ressource consuming alternative:
Route::get('{slug}', array(function($slug) {
return View::make('content')
->with('content', Article::where('slug', $slug)->first())
->with('menu', $hc->menu)
->with('isHome', false);
}))->where('slug', '^((?!admin).)*$');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community