doufei1852 2016-01-08 14:30
浏览 79
已采纳

尝试在laravel 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

The URL I am visiting is:

/admin/roles/delete/4

The route for it is:

Route::get('admin/roles/delete/{id}', ['as' => 'admin.roles.delete', 'uses' => 'Admin\RolesController@destroy']);

The controller code is:

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'));
}

The model code is:

<?php namespace App;

use Zizaco\Entrust\EntrustRole;

class Role extends EntrustRole
{
    protected $fillable = ['name', 'display_name', 'description'];
}

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',

];
  • 写回答

3条回答 默认 最新

  • duanjing2013 2016-01-15 15:10
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料