javascript - Laravel Route Generation -
i have route defined in routes.php file following:
route::get('/configuration/{id}', 'configcontroller@getconfigdetailsbyid'); i trying generate url route in blade template in tags, based on selection.
$url = '{{route('configuration', 1)}}'; but getting error, route [configuration] not defined.
also, how can use variable inside route generation. following fails error variable id not defined, although defined , initialised.
$url = '{{route('configuration', $id)}}';
you'll need give route name use that.
route::get('/configuration/{id}', 'configcontroller@getconfigdetailsbyid') ->name('configuration); as $id, wary of variable scope. may defined in controller, doesn't mean exists in view. you'll need pass view, like:
return view('configuration', ['id' => $id]); as using $id in route() call, per docs, you need pass array of data:
$url = '{{route('configuration', ['id' => 1])}}'; and that bit, can't use blade instructions in php code that, it'll more like:
$url = route('configuration', ['id' => 1]);
Comments
Post a Comment