|null $story * @property Carbon|null $expires_at * @property Carbon|null $created_at * @property Carbon|null $updated_at * @property int|null $is_archived * @property string|null $name * @property int|null $active * @property int $can_reply * @property int $can_react * @property string|null $object_id * @property string|null $object_uri * @property string|null $bearcap_token * @property-read Profile|null $profile * @property-read Collection $views * @property-read int|null $views_count * * @method static \Illuminate\Database\Eloquent\Builder|Story newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Story newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Story query() * @method static \Illuminate\Database\Eloquent\Builder|Story toAudience() * @method static \Illuminate\Database\Eloquent\Builder|Story whereActive($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereBearcapToken($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereCanReact($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereCanReply($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereCdnUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereCommentCount($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereDuration($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereExpiresAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereIsArchived($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereLocal($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereMediaUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereMime($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereObjectId($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereObjectUri($value) * @method static \Illuminate\Database\Eloquent\Builder|Story wherePath($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereProfileId($value) * @method static \Illuminate\Database\Eloquent\Builder|Story wherePublic($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereRemoteUrl($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereSize($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereStory($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereType($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Story whereViewCount($value) * * @mixin \Eloquent */ class Story extends Model { use HasSnowflakePrimary; public const MAX_PER_DAY = 20; /** * Indicates if the IDs are auto-incrementing. * * @var bool */ public $incrementing = false; protected $guarded = []; protected $visible = ['id']; protected $hidden = ['json']; protected function casts(): array { return [ 'story' => 'json', 'expires_at' => 'datetime', 'view_count' => 'integer', ]; } public function profile(): BelongsTo { return $this->belongsTo(Profile::class); } public function views() { return $this->hasMany(StoryView::class); } public function seen($pid = false) { return StoryView::whereStoryId($this->id) ->whereProfileId(Auth::user()->profile->id) ->exists(); } public function permalink() { $username = $this->profile->username; return url("/stories/{$username}/{$this->id}/activity"); } public function url() { $username = $this->profile->username; return url("/stories/{$username}/{$this->id}"); } public function mediaUrl() { return url(Storage::url($this->path)); } public function bearcapUrl() { return Bearcap::encode($this->url(), $this->bearcap_token); } /** * @return list */ public function scopeToAudience($scope): array { $res = []; switch ($scope) { case 'to': $res = [ $this->profile->permalink('/followers'), ]; break; default: $res = []; break; } return $res; } public function toAdminEntity(): array { return [ 'id' => $this->id, 'profile_id' => $this->profile_id, 'media_src' => $this->mediaUrl(), 'url' => $this->url(), 'type' => $this->type, 'duration' => $this->duration, 'mime' => $this->mime, 'size' => $this->size, 'local' => $this->local, ]; } }