Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

php - Laravel get parameters from url

I have the following in my routes

Route::get('c/maintenances/{contractor_user_id}', 'MaintenanceApiApiContractorMaintenanceController@index');

is there a way for me to get the /{contractor_user_id} by reading the url?

For example

 $current_url = Request::url();
 dd($current_url);

returns

"http://127.0.0.1:8000/api/c/maintenances/3"

Is there a way to alienate the 3 from the url and return it?

question from:https://stackoverflow.com/questions/65916129/laravel-get-parameters-from-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this request()->route('contractor_user_id');

$request->route('parameter_name')., where parameter_name refers to what we called the parameter in the route.

https://www.digitalocean.com/community/tutorials/get-laravel-route-parameters-in-middleware


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...