The problem: I'd like to resolve slugs, if a slug has been used as a route parameter instead of an id.
Attempted Solution: I'm currently getting a parameter from the request in my middleware and trying to set it back to the request. But it seems that this isn't passed to the route (it is passed to subsequent middleware)
Route:
Route::get('view_events/{gid}', array('as' => 'view_events','middleware' => ['auth','resolveGroupSlug','groupAdmin'], function($gid)
{
$user = Auth::user();
$group = Team::find($gid);
echo $gid;
//get this user's relationship to group
$group["team_user"] = Users_team::findComposite($gid,$user["id"]);
$events = Helpers::getEvents($gid,0);
return View::make('view_events', array('user' => $user, 'group' => $group, 'events' => $events));
}));
Middleware (resolveGroupSlug):
public function handle($request, Closure $next)
{
//convert a string gid to id number
if (is_string ($request->gid)) {
$group = Team::where('slug', '=', $request->gid)->firstOrFail();
$request['gid'] = $group->id;
echo $request->gid;
}
return $next($request);
}
Any ideas how to set a route parameter in middleware? Or if there is just an easier way of doing this.
(No, i'm not going to copy paste the middleware code into every route i need this in!)
Thanks!!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire