Laravel 5 Route Model Binding无法在服务器上运行

sho*_*ild 7 laravel laravel-5

我有Laravel 5路径模型绑定的问题我使用以下控制器方法

public function destroy(PrimaryLocation $primaryLocation) {
    dd($primaryLocation->id);
    $primaryLocation->delete();
    return redirect()->back()->with('locationDeleted', true);
}
Run Code Online (Sandbox Code Playgroud)

其中PrimaryLocation是一个雄辩的模型

我的RouteServiceProvider的启动功能:

public function boot(Router $router)
{
    parent::boot($router);

    $router->model('user', 'App\User');
    $router->model('PrimaryLocation', 'App\PrimaryLocation');
}
Run Code Online (Sandbox Code Playgroud)

在我的routes.php中

Route::delete('deletePrimaryLocation/{PrimaryLocation}',
              ['as' => 'admin.deletePrimaryLocation', 'uses' => 'LocationsController@destroy']);
Run Code Online (Sandbox Code Playgroud)

此设置在我的本地计算机上运行正常,但是当我将文件部署到我的开发服务器时,模型绑定会破坏; 执行该方法时,不会删除该位置.

我做了一些var_dumps

dd($primaryLocation->id); 
Run Code Online (Sandbox Code Playgroud)

在本地计算机上,它返回正确的id,但在服务器上它将返回null;

但是,如果我做了

dd($primaryLocation)
Run Code Online (Sandbox Code Playgroud)

结果是在当地

    PrimaryLocation {#178 ?
    #fillable: array:1 [?]
    #connection: null
    #table: null
    #primaryKey: "id"
    #perPage: 15
    +incrementing: true
    +timestamps: true
    #attributes: array:4 [?]
    #original: array:4 [?]
    #relations: []
    #hidden: []
    #visible: []
    #appends: []
    #guarded: array:1 [?]
    #dates: []
    #casts: []
    #touches: []
    #observables: []
    #with: []
    #morphClass: null
    +exists: true
  }
Run Code Online (Sandbox Code Playgroud)

在我的服务器上几乎相同...但缺少属性:

        PrimaryLocation {#195 ?
  #fillable: array:1 [?]
  #connection: null
  #table: null
  #primaryKey: "id"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: []
  #original: []
  #relations: []
  #hidden: []
  #visible: []
  #appends: []
  #guarded: array:1 [?]
  #dates: []
  #casts: []
  #touches: []
  #observables: []
  #with: []
  #morphClass: null
  +exists: false
}
Run Code Online (Sandbox Code Playgroud)

有没有人知道可能出错的地方?

[UPDATE]

如果我发表评论

// $router->model('PrimaryLocation', 'App\PrimaryLocation');
Run Code Online (Sandbox Code Playgroud)

在我的ServiceProvider中,本地行为与服务器上的行为相同.也许加载ServiceProvider有问题?也许有某种缓存?

jho*_*off 10

在经历了同样的问题之后,我发现在生产中,storage/framework/compiled.php不会像开发模式那样定期重建.

基本上,您只是在生产服务器上运行旧版本的RoutesServiceProvider.php.

虽然修复很容易.只要运行php artisan clear-compiled.

向任何部署脚本添加行也是一种很好的做法.

  • 神圣的废话谢谢你.我疯了 (3认同)