request() is one of the several helper functions provided in Laravel 5.2. It returns the current request object thus you don't need use statement for the facade on the top of your class.
I am using Laravel 5.1 and getting URL data with $request->segment(3) in the controller.
2
In Laravel 7, I am using this to get segments
public function my_function(Request $request )
{
// By using this, we can get the second segment in route
// Example: example.com/hh/kk
$segment = $request->segment(2);
// By using this we will get "kk"
}
Illuminate\Http\Requestfecade. If you are using any other.