Skip to content
Advertisement

Laravel how to properly pass data to href

sorry if the question is kind of newbie. I am new to php and laravel, still trying to learn through tutorial.

I am trying to pass the ‘No’ in my database to the url, so that the url when I clicked on Daftar, it will show

http://127.0.0.1:8000/search/{No}

Webpage designed

I did try to put it this way in my href tag but did not manage to get the result I want

here is my code

search.blade.php

JavaScript

searchController.php

JavaScript

web.php

JavaScript

Thank you

Advertisement

Answer

You have multiple ways to do that. In my opinion, the simplest way would be <a href="search/ {{ $nama->No] }}">DAFTAR</a>.

Actually, what you have already done. Only with the Bladesyntax. And there is a small mistake in your example. Namely, your double quotes. <a href="search/".$nama[No]>DAFTAR</a> should be:

<a href="search/<?php echo $nama[No] ?>">DAFTAR</a> or better <a href="search/ {{ $nama->No] }}">DAFTAR</a>.

For the sake of completeness. the most elegant way would be to work with components.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement