首页 > 解决方案 > 每次我在路由中添加 URL 参数时都缺少 [Route 所需的参数

问题描述

嗨,我的 order.index 中有一个 URL 参数

<a href="/order-payments/create/{{$order->id}}"><i class="fas fa-dollar-sign"></i></a>

我将 id 传递给我的 order-payments.create。但是每次我在路由中添加 {id}

Route::get('/order-payments/create/{id}', 'OrderpaymentsController@create')->name('order-payments.create');

它给了我这个错误

在此处输入图像描述

即使在其他页面中,此错误也显示在我的整个页面中。

你认为是什么导致了这个问题?提前致谢!

更新

这是我的商店并在我的 OrderpaymentsController 中创建功能

public function create()
{
    return view('order-payments.create', compact('orderpayments'));
}
public function store(Request $request)
{
    // $orderpayments = Orderpayments::create($request->only('title'));
    // return redirect(route('order-payments.index'));

    $order = Orders::all('grandtotal','currency_id','company_id','id');
    $company = Companies::all('comp_name','id');
    $currency = Currencies::all('name','acronym','id');
    $banks = Banks::all('name','acronym','id');

    // dd($currency['name']);

    return view('order-payments.create', compact('orderpayments'))
        ->with('currency', $currency)
        ->with('banks', $banks)
        ->with('order', $order)
        ->with('company', $company)
        ->with('orderId', $order->id);

    // return view('order-payments.create');
}

标签: laravel

解决方案


尝试这个:

<a href="{{ route('order-payments.create', $order->id) }}"><i class="fas fa-dollar-sign"></i></a>

确保你进入$order->id刀片文件

OrderpaymentsController.php

public function create($order_id)
{
    $orderpayments = OrderPayment::find($order_id); //your query
    return view('order-payments.create', compact('orderpayments'));
}

推荐阅读