简体   繁体   English

雄辩的路线隐式绑定Laravel 5.6无法正常工作

[英]Eloquent Route implicit binding Laravel 5.6 isn't working

I have tried to develop an application and I'd like to use route binding, but something is wrong and I don't know what it is. 我尝试开发应用程序,但想使用路由绑定,但是出了点问题,我不知道它是什么。 Plz, look code below and help me what it is wrong. 请查看下面的代码,并帮助我解决问题。

Route 路线

|        | PATCH    | api/v1/filial/{filial}                  |      | Genesis\Base\Filial\Controllers\FilialController@update                    | auth:api   |

Model 模型

class Filial extends Model{

/**
 * @var string
 */
protected $table = "filiais"; ...

Controller 控制者

class FilialController extends BaseFormController{...
    public function update(FilialRequest $request, Filial $filial){
       dd($filial);
    }...

And then the output comes as a model empty. 然后输出为空模型。 I don't know what it is wrong, parameter's, Model, Uri all these things matches. 我不知道这是什么问题,参数,模型,Uri这些东西都匹配。 I'm using Laravel 5.6 since the beginning of this project. 自从这个项目开始以来,我就在使用Laravel 5.6。

Ensure you have everything setup properly, in your kernel.php you should have: 确保已正确设置所有设置,在kernel.php您应具有:

protected $routeMiddleware = [
    ...
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ...
];

You also need to ensure you have the bindings middleware in your routes: 您还需要确保您的路由中具有绑定中间件:

Route::group(['middleware' => ['bindings'], function() {
    // routes
}

If that still isn't working I would opt to look into explicit route binding : 如果仍然无法解决问题,我将选择研究显式路由绑定

To register an explicit binding, use the router's model method to specify the class for a given parameter. 要注册显式绑定,请使用路由器的model方法为给定参数指定类。 You should define your explicit model bindings in the boot method of the RouteServiceProvider class: 您应该在RouteServiceProvider类的boot方法中定义您的显式模型绑定:

public function boot()
{
    parent::boot();

    Route::model('filial', App\Filial::class);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM