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 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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With