Here's my route :
Route::get('location/{id}/{title?}', array('as' => 'scouting_single', 'uses' => 'ScoutingController@get_single'));
The class is simple:
public function get_single($id, $title ='') {
$location = new Location;
if(is_numeric($id)) {
$location = $location->find($id);
if(isset($location)) {
$author = User::find($location->author);
$meta = $location->find($id)->metakeywords;
if($title == '') {
$slug = Str::slug($location->title);
return Redirect::to('location/'.$id.'/'.$slug);
}
return View::make('scoutingviews.view')->with('pagetitle', 'Location view')
->with('location', Location::find($id))
->with('author', $author)
->with('meta', $meta);
} else {
return Redirect::to('/')->with('message', 'That record is not available');
}
} else {
return Redirect::to('404');
}
}
Everything seems to work fine but after searching around it seems that others are doing it differently like saving the slugs to db, but I just want to include the id to the url... and make it optional to include the title slug. If the user removes the slug, it will redirect the user with the slug anyways.
I'm still learning laravel so please forgive the newbie question with regards to seo-friendliness, I just don't want /{id}/ and /{id}/{title} to count as duplicates