如何在Laravel 5中获取当前页面的段?

I have URL like this /project/1

How can I get param 1

I need it variable in another controller for another route....

here is examle:

route 1:

Route::get('project/{id}',array(
            'as'   => 'projectID',
            'uses' => 'FirstController@someMethod'
));

route 2:

Route::post('another/route',array(
            'as'   => 'another',
            'uses' => 'SecondController@anotherMethod'
    ));

I need to get inside anotherMethod id param from project/{id}... I tried like this return Request::segment(2); but it will return just segments from this route: another/route...

Any solution?

You can try this:

Controller:

public function index(Request $request){
        return $request->segment(2); //set the segment number it depends on you
    }
public function someMethod(Request $request)
{
    // If you know the segment number
    $id = $request->segment(2);

    // If you know the parameter name
    $id = $request->route('id');

    // If you only know it's the last segment
    $segments = $request->segments();
    $id = array_pop($segments);
}