[我每次在路由中添加URL参数时,都缺少[路由]必需的参数

时间:2019-03-07 08:33:51

标签: laravel

嗨,我的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');

它给了我这个错误

enter image description here

此错误显示在我的整个页面中,甚至在其他页面中。

您认为是什么导致了此问题?预先感谢!

更新

这是我在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');
}

3 个答案:

答案 0 :(得分:1)

尝试一下:

<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'));
}

答案 1 :(得分:1)

您应该使用route助手来生成URL。这样可以确保网址与路由文件中定义的网址一致。

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

答案 2 :(得分:1)

您需要为方法指定ID

      tortoise1.cs(16,25): error CS1061: 'TortoiseForm' does not contain a definition for 'carapace' and no accessible
    extension method 'carapace' accepting a first argument of type 'TortoiseForm' could be found (are you missing a using directive or an assembly reference?) [......csproj]