Laravel 资源路由id与注入注意事项

例如路由命名web.php里是 product

那你资源路由里use模型后Proudct $product这样才会返回结果$后的名字要和命名相同

否则返回的是空。

查询命名方法:php artisan route:list

 

例如红色部分必须相同

Route::resource(‘productcategory‘,’Admin\ProductCategoryController’);

public function edit(ProductCategory $productcategory)
{
    dd($productcategory);
}


  #table: "product_category"
  +timestamps: true
  #primaryKey: "cid"
  #guarded: []
  #fillable: []
  #connection: "mysql"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:12 []
  #original: array:12 []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  #hidden: []
  #visible: []