dse3168 2017-06-03 02:34
浏览 109

Laravel没有将模型加载到路线中

I'm currently developing a PHP Laravel app, and everything has been going well so far. However, my latest resouce called FreightRequest is resulting in extremely bizarre behavior that I cannot figure out.

My route file has the following:

Route::resource('freightrequests', 'FreightRequestController');

When I access http://localhost/freightrequests/1, laravel is not correctly binding the model to my FreightRequestController@show method.

My method looks like this:

public function show(FreightRequest $freightRequest)
{
    dd($freightRequest);

    return view('freightrequests.show', compact('freightRequest'));
}

The above results in the following dump:

FreightRequest {#429 ▼
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #events: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}

In fact, if I go to a non-existant ID http://localhost/freightrequests/12343243, Laravel doesn't throw NotFoundHttpException. If I visit http://localhost/users/12343243 I get a NotFoundHttpException. All of my other resources are working fine except this one resource.

I even tried to ditch the Route::resource and replace it with:

Route::get('freightrequests/{freightrequest}', 'FreightRequestController@show')->name('freightrequests.index');

I've tried renaming the model, controller, route and everything in case something was conflicting causing Laravel to no retrieve the model. It seems to be injecting the right class instance, but not actually attempting to fetch it from the server. I've tried clearing the cache. I absolutely cannot figure out why this particular model is not working where as my other 6 or so resources are working without issue.

Any ideas?

  • 写回答

1条回答 默认 最新

  • drduh44480 2017-06-03 02:42
    关注

    I found the problem shortly after posting the question:

    public function show(FreightRequest $freightRequest)
    {
       dd($freightRequest);
    
       return view('freightrequests.show', compact('freightRequest'));
    }
    

    Should be:

    public function show(FreightRequest $freightrequest)
    {
        dd($freightrequest);
    
        return view('freightrequests.show', compact('freightrequest'));
    }
    

    Case-sensitivity matters when trying to bind parameters, and it took me a very long time to realize that R was capital :)

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题