how to get url parameter in controller in laravel?

You need to add the parameter to the route. So, it should look like this:

Route::get('add/{slug}', 'HomeController@add');

And the add method:

public function add(Request $request, $slug)

Then value of the $slug variable will be Chilli Green Salad

https://laravel.com/docs/5.5/routing#required-parameters


You can do it like,

Route

Route::get('add/{data}', 'HomeController@add');

Controller

public function add(Request $request){
    // Access data variable like $request->data
}

I hope you will understand.

Tags:

Php

Laravel