How to pass variables in href in Laravel routing
P粉207969787
P粉207969787 2023-08-26 20:05:01
0
1
443
<p>I'm creating a project using Laravel 8, I've created a map using OpenLayers, the map has "points" (or features), each point has a name that's been determined, and every time I click on one of them When I click, a popup appears showing the name of the point and a link that should take me to another page showing more information, the part of the code that gave me the problem is this: </p> <pre class="brush:php;toolbar:false;">if(feature){ var text = feature.get('name'); content.innerHTML = text ' ' '<a class="nav-link" href="{{ route('local',['nombre' => text]) }}">{{ __('Ver menú') }}></a>'; }else{ content.innerHTML = ''; }</pre> <p>It threw me this error:</p> <blockquote> <p>Use of undefined constant text - assuming 'text' (this will throw an error in a future PHP version)</p> </blockquote> <p>So I'm assuming I can't pass variables like that but I don't know how, here is the route I defined: </p> <pre class="brush:php;toolbar:false;">Route::get('/local/{nombre}', 'LocalController@index')->name('local');</ pre> <p>This is the code for the controller: </p> <pre class="brush:php;toolbar:false;"><?php namespace AppHttpControllers; use IlluminateHttpRequest; class LocalController extends Controller { /*** Create a new controller instance. * * @return void*/ public function __construct() { $this->middleware('auth'); } /*** Show the application dashboard. * * @return IlluminateContractsSupportRenderable*/ public function index($nombre) { return view('local', ['nombre' => $nombre]); }</pre> <p>}</p> <p>Thank you very much for any advice/tips/information in advance (also, if the code looks a bit messy here, sorry, I'm a newbie and don't know how to give it a proper style, hehe)< /p>
P粉207969787
P粉207969787

reply all(1)
P粉250422045

I think the problem with this part is the text

{{ route('local',['nombre' =>  text]) }}

It should be like this

{{ route('local',['nombre' =>  'text']) }}

Hope it helps you

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!