Search code examples
laravelhref

Laravel send data through href


I need to send the id of the table row to the controllers show function.

Below is my function:

            <tbody>   
            @foreach($invoices as $invoice)             
            <tr>
                <th scope="row">{{ $invoice->total_subcriptions }}</th>
                <td>{{ $invoice->description }}</td>
                <td>{{ $invoice->product_id }}</td>
                <td>Rs.{{ $invoice->total }}</td>
                <td>Not Paid</td>                    
                <th><a href="{{ url('/invoice/(ID here)') }}" class="btn btn-sm btn-info">View</a></th>
            </tr>
            @endforeach
            </tbody>    

How can I send it directly?

This didnt work for me and showed a syntax error:

Exception message: Parse error: syntax error, unexpected '}', expecting ',' or ')'

<th><a href="{{ url('/invoice/{{$invoice->id}}') }}" class="btn btn-sm btn-info">View</a></th>

Solution

  • Looks like you need to concat your url string.

    <th><a href="{{ url('/invoice/{{$invoice->id}}') }}" class="btn btn-sm btn-info">View</a></th>
    

    should be

    <th><a href="{{ url('/invoice/'.$invoice->id) }}" class="btn btn-sm btn-info">View</a></th>