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条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭