Evaldas Butkus
Evaldas Butkus

Reputation: 665

Laravel 5.0 pass variable to middleware

At the moment I have to check if job record, which is being edited, belongs to right person. My get job edit route:

/user/job-edit/{slug}

So I created JobEditMiddleware but the problems is I can't access {slug} variable in my middlewar. Is there any way to do it? Thanks.

Upvotes: 0

Views: 105

Answers (2)

Disfigure
Disfigure

Reputation: 740

You can access to your slug parameter easier.

public function handle($request, Closure $next, $role) {
 //
}

You have to call your slug parameter like this :

$request->slug;

I think it's a better way than segment if you'll need to change your route later.

Upvotes: 1

pinkal vansia
pinkal vansia

Reputation: 10330

You can use segment() method to retrieve various segments of your URI.

Try following in your middleware,

\Request::segment(3)

Read More

Upvotes: 4

Related Questions