rur2641 rur2641 - 11 days ago 5
PHP Question

Hypertext to route not working

Hi I have a hyperlink from a page:

<h3><a href="hitest">hitest</a></h3>

the route:

Route::get('hitest', function(){ return 'hitest message';});

There is an error:

No query results for model [App\User2].

hyper link is from a page with this url


the 1 is a model object.

Shouldn't the hyperlink route to /hitest ?
Please see my other post: Strange behavior with routing and hypertext.
I'm new at web development. Is there configurations for routing? The app is hosted (not local).


As bytesarelife already mentioned, you can use the url()-function, like so:

{{ url('your/url/') }}

A better way in terms of maintainability would be to give your routes names, so you would not have to replace every url in every template once you want to change it. You can do so, by adding the name in your routes:

Route::get('hitest', function(){ return 'hitest message';})->name('getHittest');

And then you can use the route function in your view:

{{ route('getHittest') }}