Laravel 5.5 Spatie 权限不创建角色
Laravel 5.5 Spatie Permission doesn't create role
我正在使用 laravel 5.5 和 spatie / laravel-permission ":" ^ 2.38 "。我创建了一个用于创建角色的简单控制器,但是 laravel returns 错误:
Illuminate \ Database \ Eloquent \ MassAssignmentException
"name"
My simple controller is:
<?php
namespace App;
namespace App\Http\Controllers\UserRole;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Model;
use App\Role;
use App\Permission;
use DB;
class RolePermission extends Controller
{
public function create_role(){
Role::create(['name' => 'noc']);
}
}
问题与 Spatie 无关。您必须允许 Role 对象是可批量分配的。在您的情况下,您必须输入:
protected $fillable = ['name'];
您的榜样,或:
protected $guarded = [];
查看更多here
我正在使用 laravel 5.5 和 spatie / laravel-permission ":" ^ 2.38 "。我创建了一个用于创建角色的简单控制器,但是 laravel returns 错误:
Illuminate \ Database \ Eloquent \ MassAssignmentException "name" My simple controller is:
<?php
namespace App;
namespace App\Http\Controllers\UserRole;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Model;
use App\Role;
use App\Permission;
use DB;
class RolePermission extends Controller
{
public function create_role(){
Role::create(['name' => 'noc']);
}
}
问题与 Spatie 无关。您必须允许 Role 对象是可批量分配的。在您的情况下,您必须输入:
protected $fillable = ['name'];
您的榜样,或:
protected $guarded = [];
查看更多here