Laravel 5路由模型绑定在服务器上不工作
我对Laravel 5路线模型绑定有问题 我使用以下控制器方法Laravel 5路由模型绑定在服务器上不工作,laravel,laravel-5,Laravel,Laravel 5,我对Laravel 5路线模型绑定有问题 我使用以下控制器方法 public function destroy(PrimaryLocation $primaryLocation) { dd($primaryLocation->id); $primaryLocation->delete(); return redirect()->back()->with('locationDeleted', true); } PrimaryLocation是一个雄
public function destroy(PrimaryLocation $primaryLocation) {
dd($primaryLocation->id);
$primaryLocation->delete();
return redirect()->back()->with('locationDeleted', true);
}
PrimaryLocation是一个雄辩的模型
My RouteService Provider的启动功能:
public function boot(Router $router)
{
parent::boot($router);
$router->model('user', 'App\User');
$router->model('PrimaryLocation', 'App\PrimaryLocation');
}
在my routes.php中
Route::delete('deletePrimaryLocation/{PrimaryLocation}',
['as' => 'admin.deletePrimaryLocation', 'uses' => 'LocationsController@destroy']);
这个设置在我的本地计算机上运行良好,但是当我将文件部署到开发服务器时,模型绑定会中断;
执行该方法时不会删除该位置
我做了一些var_Dump
dd($primaryLocation->id);
在本地计算机上,它返回正确的id,但在服务器上它将返回正确的id
只需返回null
但是如果我做了一个
dd($primaryLocation)
结果是局部的
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
}
在我的服务器上几乎相同。。。但缺少以下属性:
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
}
有人知道哪里出了问题吗
[更新]
如果我不加评论
// $router->model('PrimaryLocation', 'App\PrimaryLocation');
在me ServiceProvider中,本地行为与服务器上的行为相同。
加载服务提供商可能有问题?也许有某种缓存 在经历了同样的问题之后,我发现在生产环境中,
存储/framework/compiled.php
不像在开发模式中那样定期重建
基本上,您只是在生产服务器上运行RouteServiceProvider.php的旧版本
不过,解决这个问题很容易。只需运行php artisan clear compiled
将这一行添加到任何部署脚本中也是一个很好的做法。只需将这一行添加到serviceProvider::boot()中即可
缺少的
属性是因为找不到记录。数据库中的数据是否相同?i、 e.相同的数据库、表和字段?特别是-记录本身是否存在?服务器上的文件名是否正确?它的大小写敏感度是否相同?如果它找不到记录,则应该有404错误(至少文档中说明了这一点),如果我是正确的。如果文件名不正确,就会出现某种“硬”错误。。。(哎哟,出了点问题)是的-正确-但我只是想排除各种问题。只是想澄清一下-问题是没有找到记录。我不知道为什么它不抛出404,但事实上你得到id
的null
就是证明。另外,当您dd()
时,您可以清楚地看到存在的对象:false
。因此,我们需要确认该记录实际上在数据库中,然后从那里计算出来。
$router->model('attribute', Attribute::class);