Laravel ,不能将 php 放入 href link

Laravel ,can't put php in the href link

我只想制作一个按钮,将我重定向到类似这样的内容/loans/loans->id/edit"

其中 loans->id 来自数据库,他的 href 应该怎么看?

<button href="{{ URL('/loans/{{$loan->id}}/edit')}}" 

这是我到目前为止所拥有的,但出现错误

首先你需要在标签中写上href了!您可以使用帮助路线

<a htef="{{route('loans.edit',[$loans->id])}}">link</a>

然后在路由器的文件中,写

 Route::get('loans/{$id}/edit', 'yourcontroller@method')->name('loans.edit')

您正在另一个内部编写 blade 大括号,这将引发解析错误。因为会翻译成这段代码。

<button href="<?php echo e(URL('/loans/{{$loan->id); ?>/edit')}}" 

此外,如果您想在字符串中编写表达式,请使用双引号 ""{} 单花括号。

试试这个。

<button href="{{ URL("/loans/{$loan->id}/edit") }}" 

也在你的路由文件中添加这条路由。

Route::get('/loans/{id}/edit', 'controller@method');

你的 href 应该是这样的

href='loans/{{$load->id}}/edit'

并且您的 \routs\web.php

中应该包含以下内容
Route::get('/loans/{loan}/edit', 'LoansController@edit');