SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'model_id' cannot be null (SQL: insert into `ks_model_has_permissions` (`model_id`, `model_type`, `permission_id`) values (, App\User, 2))
$user->givePermissionTo('add articles');
app\User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use Notifiable;
use HasRoles;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
app\Http\Controllers\HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use app\User;
class HomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(User $user)
{
$user->givePermissionTo('add articles');
}
}
1
xoxo419 OP 已解决: 详见-> [传送门]( https://segmentfault.com/q/1010000012374893)
|