当我尝试将ID传递给另一个控制器时,我不知道为什么会出现404 not found错误。
这是我的index.blade.php
<a class="btn btn-sm btn-default" href="{{ route('receiving_details',
['id'=>$r_main->id])}}" title="Show Received Data"><i class="fa fa-arrow
right"</i></a>
web.php
Route::get('receiving_details/{$id}',[
"uses" => 'ReceivingDetailsController@index',
"as" => 'receiving_details'
]);
ReceivingDetailsController.blade.php(这是我要从view.blade.php传递ID的地方)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ReceivingDetailsController extends Controller
{
public function index($id){
echo $id;
}
}
答案 0 :(得分:1)
只需从获取请求中删除$
。
Route::get('receiving_details/{id}',[
"uses" => 'ReceivingDetailsController@index',
"as" => 'receiving_details'
]);
答案 1 :(得分:-1)
在您的href中,请稍加调整
<a class="btn btn-sm btn-default" href="{{ route('receiving_details', $r_main->id)}}" title="Show Received Data"><i class="fa fa-arrow right"</i></a>