I'm trying to create href
with route laravel. This route contains a parameter, but it always returns Error 404 . I don´t know what I´m doing wrong.
I know that my question is very easy, I´m searching in Google for this, but I think that I'm doing well on my route.
My route:
/** SHOW EVENT INFO */
Route::get('event/{url}', 'Web\EventController@showEvent');
My href in file.js
:
<a target="_blank" id="button-event-read" href="'+config.url.base_url+'event/'+eventUrl+'" class="btn color2-bg float-btn">Leer más.<i class="fal fa-angle-right"></i></a>
If I click in href, it goes to the correct route but ends up showing Error 404 .
My controller:
public function showEvent($url){
echo "here";
}
you can use route name
add a name to your route:
/** SHOW EVENT INFO */
Route::get('event/{url}', 'Web\EventController@showEvent')->name('MyRouteName');
and use the route name in href:
<a target="_blank" id="button-event-read" href="{{route('MyRouteName', 'MyParameter')}}" class="btn color2-bg float-btn">Leer más.<i class="fal fa-angle-right"></i></a>
Get Host url in variable
var url = window.location.protocol + "//" + window.location.host;
and then use it in href like this.
<a target="_blank" id="button-event-read" href="'+url+'/event/'+eventUrl+'" class="btn color2-bg float-btn">Leer más.<i class="fal fa-angle-right"></i></a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.