Laravel 5 setting route parameter from middleware -
the problem: i'd resolve slugs, if slug has been used route parameter instead of id.
attempted solution: i'm getting parameter request in middleware , trying set request. seems isn't passed route (it passed 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 user's relationship 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 string gid 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 set route parameter in middleware? or if there easier way of doing this.
(no, i'm not going copy paste middleware code every route need in!)
thanks!!
the new value wont passed parameter in route closure. need $request->request->get('gid');
try dd($gid, $request->request->get('gid')); , compare.
or $request->gid
proxy same methodcall
Comments
Post a Comment