I have defined a dummy route like this:
Route::get('sth/{v1}/{v2}' , [
'uses'=>'SthController@sth',
]) ;
how can I get the value of v1 and v2, outside controllers?
I have defined a dummy route like this:
Route::get('sth/{v1}/{v2}' , [
'uses'=>'SthController@sth',
]) ;
how can I get the value of v1 and v2, outside controllers?
use this code
$current_params = Route::current()->parameters();
dd($current_params->v1) ;
You can get the values of v1 and v2 anywhere like this:
request()->v1;
request()->v2;
In Laravel 5.6 for me it was:
Route::current()->parameters['v1']
Route::current()->parameters['v2']
etc...
You can use the laravel helper named: request()
$value = request('key', $default);
For your route you can use
$v1 = request('v1','default data');
$v2 = request('v2','default data');
Laravel documentation: request helper laravel
haven't tried but think its Route::current()
, use from anywhere to access the parameters
$currentParams = Route::current()->parameters();
You can put the data in session in controller when pass, then from anywhere you can get your desire data,
Session::put('v1');
Session::put('v2');
now anywhere you can access like:
Session::get('v1')
Session::get('v2')
if you need to delete session data just use
Session::forget('v1')
Session::forget('v2')