duanguangsong2380 2017-09-01 19:39
浏览 370
已采纳

Laravel 5.5空对象

Good afternoon guys, I'm having an issue I don't know if you have the same trouble, I upgrade my Laravel project and now all routes like this

Route::get('detail/client/{client}', "controller@method")

are breaking everything because the object instanced in the controller comes empty...

public function detail(FileRequest $request, Client $client){

 dd($client) // empty object
}

If someone can help me with this please. If I remove the Client model and make the dd then return the ID of the object i.e "594"

  • 写回答

1条回答 默认 最新

  • duanjiao5543 2017-09-01 20:09
    关注

    You haven't written base Laravel version you are upgrading from, but I think it might have something in common with \Illuminate\Routing\Middleware\SubstituteBindings::class middleware.

    Make sure you have it in middlwareGroups like this:

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class, // <- this is the line you should have
        ],
        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];
    

    in app/Http/Kernel.php file

    and also make sure the routes you have problem are in web middleware group.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM