|null $metadata * @property Carbon|null $created_at * @property Carbon|null $updated_at * @property int|null $member_count * @property int $recommended * @property int $discoverable * @property int $activitypub * @property int $is_nsfw * @property int $dms * @property int $autospam * @property int $verified * @property string|null $last_active_at * @property Carbon|null $deleted_at * @property-read Profile|null $admin * @property-read Collection $members * @property-read int|null $members_count * * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Group onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Group query() * @method static \Illuminate\Database\Eloquent\Builder|Group whereActivitypub($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereAutospam($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereCategoryId($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereDiscoverable($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereDms($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereInboxUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereIsNsfw($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereIsPrivate($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereLastActiveAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereLocal($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereLocalOnly($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereMemberCount($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereMetadata($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereProfileId($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereRecommended($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereRemoteUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereRules($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereVerified($value) * @method static \Illuminate\Database\Eloquent\Builder|Group withTrashed(bool $withTrashed = true) * @method static \Illuminate\Database\Eloquent\Builder|Group withoutTrashed() * * @mixin \Eloquent */ class Group extends Model { use HasFactory, HasSnowflakePrimary, SoftDeletes; /** * Indicates if the IDs are auto-incrementing. * * @var bool */ public $incrementing = false; protected function casts(): array { return [ 'metadata' => 'json', ]; } public function url() { return url("/groups/{$this->id}"); } public function permalink($suffix = null) { if (! $this->local) { return $this->remote_url; } return $this->url().$suffix; } public function members() { return $this->hasMany(GroupMember::class); } public function admin() { return $this->belongsTo(Profile::class, 'profile_id'); } public function isMember($id = false) { $id = $id ?? request()->user()->profile_id; // return $this->members()->whereProfileId($id)->whereJoinRequest(false)->exists(); return GroupService::isMember($this->id, $id); } public function getMembershipType(): string { return $this->is_private ? 'private' : ($this->local ? 'local' : 'all'); } public function selfRole($id = false) { $id = $id ?? request()->user()->profile_id; return optional($this->members()->whereProfileId($id)->first())->role ?? null; } }