Hax0r
Hax0r

Reputation: 1803

How can i get uri segment in routes?

I am new to laravel and my laravel version is 5.5

In my routes file. I call Segment method in Request class

Like below :

var_dump(Request::segment(1));

And then it returns this message

Non-static method Illuminate\Http\Request::segment() should not be called statically

So... do I need to make new Request instance?

Or is there any more effective way to achieve what I want?

Any suggestion or advice would be appreciated.

Thank you in advance

Upvotes: 3

Views: 3992

Answers (3)

Niket Joshi
Niket Joshi

Reputation: 748

You have to use request as

request()->segment(1)

so that error were removed.

and request->segment(1) is not correct way but request()->segment(1) is correct way to do.

i hope this works for you.

Upvotes: 1

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

You can also use the request() global helper

request()->segment(1)

Upvotes: 5

Gulmuhammad Akbari
Gulmuhammad Akbari

Reputation: 2036

You have to use Request class before that.

use Request;
var_dump(Request::segment(1));

Upvotes: 4

Related Questions