首页 > 解决方案 > Laravel 通过 href 发送数据

问题描述

我需要将表格行的 id 发送到控制器显示功能。

以下是我的功能:

            <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>    

怎么直接寄?

这对我不起作用并显示语法错误:

异常消息:解析错误:语法错误,意外'}',期待','或')'

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

标签: laravelhref

解决方案


看起来你需要连接你的 url 字符串。

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

应该

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

推荐阅读