Search code examples
phplaravelhref

php - How to set a href url in blade


I'm currently working with Laravel (because my school told me to) and php and I really don't get it. I'm working with blade.php which recieves values from a ViewControlle(not quite if it works like this but I think so). The value contains name and and a url for wikipedia which leads to the right article for the name in a table.

So what I'm trying to accomplish is

<a href="https://en.wikipedia.org/wiki/Berlin">Berlin</a>

So my code is currently:

@foreach($cities as $city)
<td>
<tr><a href="{{$city["Url"]}}">{{$city["Name"]}}</a></tr>
</td>
@endforeach

and it does not work while

@foreach($cities as $city)
<td>
<tr>{{$city["Name"]}}</tr>
</td>
@endforeach

works perfectly fine...

I've already searched for an answer but all answers are written for php with

echo '...';

I really don't get it.

Thanks in advance ^^


Solution

  • change

    <tr><a href="{{$city["Url"]}}">{{$city["Name"]}}</a></tr>
    

    to

     <tr><a href="{{$city['Url']}}">{{$city["Name"]}}</a></tr>
    

    or you can do it like this:

    <tr><a href='{{$city["Url"]}}'>{{$city["Name"]}}</a></tr>