Reputation: 1803
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
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
Reputation: 163768
You can also use the request()
global helper
request()->segment(1)
Upvotes: 5
Reputation: 2036
You have to use Request class before that.
use Request;
var_dump(Request::segment(1));
Upvotes: 4