I have a site that displays home, about, and archives by date OR topic.
So my url structure is:
myApp/home
myApp/about
myApp/archives
myApp/archive/topic/{topic}
myApp/archives/date/{date}
There's so many ways to handle the routing for this.
I could create individual routes for each url in routes.php.
I could create a single controller and single route in routes.php and handle each url in a method.: Route::controller('/', 'FrontController')
I could create three controllers, one for each subtopic.
Just wondering if there's a best practice way and/or how more experienced peeps would handle this.
Thanks in advance!
By all means experiment with different ways, I don't think theres any right/wrong answers when it comes to questions like this one. I would go about creating a PagesController and an ArchiveController.
// routes.php
// Static Pages
Route::get('/', ['as' => 'home', 'uses' => 'PagesController@showLandingPage']);
Route::get('/about', 'as' => 'about', 'uses' => 'PagesController@showAboutUsPage']);
// Archives
Route::get('/archives', ['as' => 'list-archives', 'uses' => 'ArchiveController@listRecentArchives']);
Route::get('/archives/topic/{slug}', ['as' => 'browse-by-topic', 'uses' => 'ArchiveController@browseByTopic']);
Route::get('/archives/date/{date}', ['as' => 'list-archives', 'browse-by-date' => 'ArchiveController@browseByDate']);
// PagesController.php
class PagesController extends BaseController {
public function showLandingPage()
{
return View::make('static.home');
}
public function showAboutUsPage()
{
return View::make('static.about');
}
}
// ArchivesController.php
class ArchivesController extends BaseController {
public function listRecentArchives()
{
// Get recent archives from wherever they are stored
$archives = [];
return View::make('archives.index')->withArchives($archives);
}
public function browseByTopic($slug)
{
// Get archives from wherever stored using the topic slug
$archives = [];
return View::make('archives.browse')->withArchives($archives);
}
public function browseByDate($date)
{
// Get archives from wherever stored using the date provided
$archives = [];
return View::make('archives.browse')->withArchives($archives);
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community