Flarum\Core\Group::build PHP Method

build() public static method

Create a new group.
public static build ( string $nameSingular, string $namePlural, string $color, string $icon ) : static
$nameSingular string
$namePlural string
$color string
$icon string
return static
    public static function build($nameSingular, $namePlural, $color, $icon)
    {
        $group = new static();
        $group->name_singular = $nameSingular;
        $group->name_plural = $namePlural;
        $group->color = $color;
        $group->icon = $icon;
        $group->raise(new GroupWasCreated($group));
        return $group;
    }

Usage Example

Beispiel #1
0
 /**
  * @param CreateGroup $command
  * @return Group
  * @throws PermissionDeniedException
  */
 public function handle(CreateGroup $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertCan($actor, 'createGroup');
     $group = Group::build(array_get($data, 'attributes.nameSingular'), array_get($data, 'attributes.namePlural'), array_get($data, 'attributes.color'), array_get($data, 'attributes.icon'));
     $this->events->fire(new GroupWillBeSaved($group, $actor, $data));
     $this->validator->assertValid($group->getAttributes());
     $group->save();
     $this->dispatchEventsFor($group, $actor);
     return $group;
 }