Laravel 8 路由模型绑定不返回 ant 记录?

问题描述 投票:0回答:2

我使用下面的代码进行路由模型绑定,但绑定变量不返回任何值。 我的路线

Route::resource('offertypes', 'OfferTYpeController');

控制器代码

    public function edit(OfferType $offerType)
    {
        dd($offerType);
        return view('admin.offer-types._form', compact('offerType'));
    }

刀片文件代码

<td>
 <a href="{{ route('admin.offertypes.edit', $offerType->id) }}">{{ ucwords($offerType->title) }}</a>
</td>

返回值 my code returns this

laravel laravel-8 route-model-binding
2个回答
2
投票

您必须使用类似的路由参数作为变量

意味着你的路线应该是这样的

Route::get('edit/{offerType}', [SomeController::class, 'edit']);

注意:

offerType
参数和方法变量中的输入完全相同。

另一个问题可能是如果您在

app\Http\Kernel.php

中错误地评论了此中间件


0
投票

offerType 与参数和方法变量中的类型完全相同

© www.soinside.com 2019 - 2024. All rights reserved.