场景:
项目迁移后 初始化角色的权限
案列解析:
代替了array_filter, 没啥必要性不这样话的也可以的
Collection::macro('forOperator', function() { return $this->filter(function ($value) { return preg_match( '/(add|edit|view|delete) (customer|service|fund|charge|profile)/', $value ); }); }); $operator = Role::create(['name' => 'operator']); $operator->givePermissionTo(Permission::all(['name'])->forOperator()->toArray());