my view blade .....
tableHtml += "<td><a href= '{{url('/add')}}/" + data.hits[i].recipe.label + "'> add to favotite</a></td>";
when i click add to fav....i get this in url
http://localhost/lily/public/add/Chilli%20Green%20Salad
web.php
Route::get('/add', 'HomeController@add');
how can i get the url pass name in controller .....
public function add(Request $request)
{
$request->get("") ////////////how can i get the string i passed on url
}
You may use the current, currentRouteName, and currentRouteAction methods on the Route facade to access information about the route handling the incoming request: $route = Route::current(); $name = Route::currentRouteName(); $action = Route::currentRouteAction();
Routing in Laravel allows you to route all your application requests to their appropriate controller. The main and primary routes in Laravel acknowledge and accept a URI (Uniform Resource Identifier) along with a closure, given that it should have to be a simple and expressive way of routing.
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
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