尝试在laravel 5.2中删除模型时引发异常 [英] Exception being thrown when trying to delete model in laravel 5.2
问题描述
我最近将Laravel 5.1应用程序升级到5.2.在此之前,它运行良好,但是自升级以来,我遇到了一个问题.当我尝试删除其中一个模型时,出现以下异常:
I have recently upgraded a Laravel 5.1 app to 5.2. This was working fine before but since the upgrade I am experiencing an issue. When I try to delete one of my models I get the following exception:
FatalErrorException in Model.php line 1011:
Class name must be a valid object or a string
我要访问的URL是:
/admin/roles/delete/4
路线是:
Route::get('admin/roles/delete/{id}', ['as' => 'admin.roles.delete', 'uses' => 'Admin\RolesController@destroy']);
控制器代码为:
public function destroy($id)
{
$role = Role::find($id);
$role->delete();
Session::flash('message', '<div class="alert alert-success" role="alert">The role has been deleted.</div>');
return redirect(route('admin.roles'));
}
型号代码为:
<?php namespace App;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
protected $fillable = ['name', 'display_name', 'description'];
}
也许值得一提的是,我正在使用 Entrust 软件包.这是我的委托配置文件的内容:
It's probably worth mentioning I'm using the Entrust package. This is the content of my entrust config file:
<?php
/**
* This file is part of Entrust,
* a role & permission management solution for Laravel.
*
* @license MIT
* @package Zizaco\Entrust
*/
return [
/*
|--------------------------------------------------------------------------
| Entrust Role Model
|--------------------------------------------------------------------------
|
| This is the Role model used by Entrust to create correct relations. Update
| the role if it is in a different namespace.
|
*/
'role' => 'App\Role',
/*
|--------------------------------------------------------------------------
| Entrust Roles Table
|--------------------------------------------------------------------------
|
| This is the roles table used by Entrust to save roles to the database.
|
*/
'roles_table' => 'roles',
/*
|--------------------------------------------------------------------------
| Entrust Permission Model
|--------------------------------------------------------------------------
|
| This is the Permission model used by Entrust to create correct relations.
| Update the permission if it is in a different namespace.
|
*/
'permission' => 'App\Permission',
/*
|--------------------------------------------------------------------------
| Entrust Permissions Table
|--------------------------------------------------------------------------
|
| This is the permissions table used by Entrust to save permissions to the
| database.
|
*/
'permissions_table' => 'permissions',
/*
|--------------------------------------------------------------------------
| Entrust permission_role Table
|--------------------------------------------------------------------------
|
| This is the permission_role table used by Entrust to save relationship
| between permissions and roles to the database.
|
*/
'permission_role_table' => 'permission_role',
/*
|--------------------------------------------------------------------------
| Entrust role_user Table
|--------------------------------------------------------------------------
|
| This is the role_user table used by Entrust to save assigned roles to the
| database.
|
*/
'role_user_table' => 'role_user',
];
推荐答案
看起来像Entrust尚未与Laravel 5.2完全兼容.我在Github上提出了这个问题,其他人也遇到了同样的问题.
Looks like Entrust just isn't fully compatible with Laravel 5.2 yet. I've raised this issue on Github and others are having the same problem.
https://github.com/Zizaco/entrust/issues/472
这篇关于尝试在laravel 5.2中删除模型时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!