You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have added a new field named salary in roles table using new migration add_salary_to_roles_table with following code:
public function up(): void
{
Schema::table('roles', function (Blueprint $table) {
$table->string('salary')->after('short_name')->default(0)->nullable();
});
}
Here is the current structure of roles table:
Note: I have added a new field named short_name before. But, there was no problem with web guard.
It has been created a new field salary on roles table. But, when I try to create a role with necessary data, it returns an error like: 'There is no permission named salary for guard web'.
Here is the controller code:
foreach ($request->all() as $key => $value) {
if ($key != '_token' && $key != 'role_name' && $key != 'short_name' && substr($key, -7) != '_module') {
$permissions[] = $key;
}
}
// create role
$role = Role::create([
'name' => $request->role_name,
'short_name' => $request->short_name,
'salary' => $request->salary
]);
// give requested permissions to role
foreach ($permissions as $item) {
$role->givePermissionTo($item);
}
In here, Role is creating perfectly with salary value, but problem is occuring when trying to give permissions to the Role.
Help me please...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I have added a new field named
salary
inroles
table using new migrationadd_salary_to_roles_table
with following code:Here is the current structure of
roles
table:Note: I have added a new field named
short_name
before. But, there was no problem withweb
guard.It has been created a new field
salary
onroles
table. But, when I try to create a role with necessary data, it returns an error like: 'There is no permission namedsalary
for guardweb
'.Here is the controller code:
In here, Role is creating perfectly with salary value, but problem is occuring when trying to give permissions to the Role.
Help me please...
Beta Was this translation helpful? Give feedback.
All reactions