I am trying to break out a resource ("fans") into separate routes so I can have custom urls for the individual resource pages, as opposed to using just $id.
So instead of this:
Route::resource('fans', 'FansController');
I have broken it into this:
Route::get('fans/{url_tag}', array('as' => 'customUrl', function($url_tag)
{
$fan = Fan::where('url_tag','=',$url_tag);
return View::make('fans.show', compact('fan'));
}))
->where('url_tag', '[A-Za-z]+');
Route::get('fans/{id}', function($id)
{
// do something with $id or
return Redirect::route('customUrl');
})
->where('id', '[0-9]+');
In the fans controller, I have this:
public function show($id)
{
$fan = Fan::find($id);
return View::make('fans.show', compact('fan'))
->with('fans', Fan::all())
->with('latest_fan_likes', Fanartist::latest_profile_fan_likes($id));
}
Basically I would like the page /fans/$id to appear as /fans/$url_tag (where url_tag is another column in the db, that is unique). But I would like it to have all of the properties of the resource, so I can call $fan->column directly.
When I run this, I get the error:
Some mandatory parameters are missing ("url_tag") to generate a URL for route "customUrl".
Any idea what is going on or what is wrong? I am using Laravel 4. Thank you.