/** * Get the guest's group, containing only the 'guests' group model. * * @return \Flarum\Core\Models\Group */ public function getGroupsAttribute() { if (!isset($this->attributes['groups'])) { $this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get(); } return $this->attributes['groups']; }
/** * @param CreateGroup $command * @return Group */ public function handle(CreateGroup $command) { $actor = $command->actor; $data = $command->data; $this->forum->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')); event(new GroupWillBeSaved($group, $actor, $data)); $group->save(); $this->dispatchEventsFor($group); return $group; }
/** * Bootstrap the application events. * * @return void */ public function boot() { Group::setValidator($this->app->make('validator')); $events = $this->app->make('events'); $events->listen(ModelAllow::class, function (ModelAllow $event) { if ($event->model instanceof Group) { if ($event->actor->hasPermission('group.' . $event->action)) { return true; } } }); }
/** * Find a user by ID, optionally making sure it is visible to a certain * user, or throw an exception. * * @param int $id * @param User $actor * @return Group * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function findOrFail($id, User $actor = null) { $query = Group::where('id', $id); return $this->scopeVisibleTo($query, $actor)->firstOrFail(); }
/** * Get the groups, ready to be serialized and assigned to the document * response. * * @param JsonApiRequest $request * @param Document $document * @return \Illuminate\Database\Eloquent\Collection */ protected function data(JsonApiRequest $request, Document $document) { return Group::all(); }
protected function seedGroups() { Group::unguard(); $groups = [['Admin', 'Admins', '#B72A2A', 'wrench'], ['Guest', 'Guests', null, null], ['Member', 'Members', null, null], ['Mod', 'Mods', '#80349E', 'bolt']]; foreach ($groups as $group) { Group::create(['name_singular' => $group[0], 'name_plural' => $group[1], 'color' => $group[2], 'icon' => $group[3]]); } }
/** * Get the forum, ready to be serialized and assigned to the JsonApi * response. * * @param JsonApiRequest $request * @param Document $document * @return \Flarum\Core\Forum */ protected function data(JsonApiRequest $request, Document $document) { $forum = app('flarum.forum'); $forum->groups = Group::whereVisibleTo($request->actor)->get(); return $forum; }