i am using spatie role and permission package and i am getting this error when i want to add permission to role There is no permission named onfor guardweb.
<?php
namespace App\Http\Livewire\Admin\App\Roles;
use Livewire\Component;
use Illuminate\Http\Response;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class Index extends Component
{
public $permissions = [];
public $create;
public $name;
protected $rules = [
'name' => 'required|min:4',
];
public function create()
{
if (auth()->check()) {
$this->validate();
$roles = Role::create([
'name' => $this->name,
]);
$roles->syncPermissions($this->permissions);
session()->flash('success', 'role was added successfully!');
$this->reset();
return redirect()->route('admin.roles.list');
}
abort(Response::HTTP_FORBIDDEN);
}
public function render()
{
$permission = Permission::get();
return view('livewire.admin.app.roles.index',[
'permission' => $permission,
]);
}
}
blade
<div>
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Create New Role</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('admin.roles.list') }}"> Back</a>
</div>
</div>
</div>
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form wire:submit.prevent="create" action="" class="">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input wire:model.defer="name" type="text" class="">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Permission:</strong>
@foreach($permission as $value)
<label><input wire:model.defer="permissions" type="checkbox" class="">
{{ $value->name }}</label>
@endforeach
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="bg-purple-400">Submit</button>
</div>
</div>
</form>
</div>
seeder
public function run()
{
$permissions = [
'role-list',
'role-create',
'role-edit',
'role-delete',
'post-list',
'post-create',
'post-edit',
'post-delete',
'comment-list',
'comment-create',
'comment-edit',
'comment-delete',
'channel-list',
'channel-create',
'channel-edit',
'channel-delete'
];
foreach ($permissions as $permission) {
Permission::create(['name' => $permission]);
}
}
}