PHP   发布时间:2022-04-05  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-Laravel隐式模型绑定命名约定?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我在控制器动作上使用了隐式模型绑定,但是我有一个名为VerifiedDocument的模型,无论我将什么作为模型名称输入,我似乎都无法将其加载到动作中,但是如果这样做:

    Route::bind('verificationDocument', function ($value) {
        return VerificationDocument::where('id', $value)->first() ?? abort(404);
    });

有用.

Laravel对隐式模型绑定使用什么命名约定?

解决方法:

IIRC隐式绑定的命名约定在参数名称和类型提示的变量名称之间,即:

// Route declaration
Route::get('verificationdocuments/{verification_document}', YourController@show);

// Controller Action
public function show(VerificationDocument $verification_document)

// or without controller
Route::get('documents/{document}', function (VerificationDocument $document) {
    return $document->title;
});

请注意,{verification_document} => $verification_document和{document} => $document

大佬总结

以上是大佬教程为你收集整理的php-Laravel隐式模型绑定命名约定?全部内容,希望文章能够帮你解决php-Laravel隐式模型绑定命名约定?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: