2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-04-15 23:08:16 +00:00
|
|
|
use App\DataTransferObjects\MediaItem;
|
2026-05-04 18:17:48 +00:00
|
|
|
use App\Enums\Media\Type;
|
2026-07-24 14:19:01 +00:00
|
|
|
use App\Enums\Post\CreatedVia;
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\Post\Status as PostStatus;
|
2026-06-28 20:28:05 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
2026-06-10 20:19:32 +00:00
|
|
|
use App\Observers\PostObserver;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Database\Factories\PostFactory;
|
2026-06-10 20:19:32 +00:00
|
|
|
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2026-04-15 23:08:16 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2026-01-26 18:18:35 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-04-15 23:08:16 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2026-05-04 18:17:48 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2026-01-15 01:13:44 +00:00
|
|
|
|
2026-06-10 20:19:32 +00:00
|
|
|
#[ObservedBy([PostObserver::class])]
|
2026-01-15 01:13:44 +00:00
|
|
|
class Post extends Model
|
|
|
|
|
{
|
2026-03-29 22:24:28 +00:00
|
|
|
/** @use HasFactory<PostFactory> */
|
2026-01-15 01:13:44 +00:00
|
|
|
use HasFactory, HasUuids;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'workspace_id',
|
|
|
|
|
'user_id',
|
2026-04-15 23:08:16 +00:00
|
|
|
'content',
|
|
|
|
|
'media',
|
2026-01-15 01:13:44 +00:00
|
|
|
'status',
|
2026-07-24 14:19:01 +00:00
|
|
|
'created_via',
|
2026-01-15 01:13:44 +00:00
|
|
|
'scheduled_at',
|
|
|
|
|
'published_at',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'status' => PostStatus::class,
|
2026-07-24 14:19:01 +00:00
|
|
|
'created_via' => CreatedVia::class,
|
2026-04-15 23:08:16 +00:00
|
|
|
'media' => 'array',
|
2026-01-15 01:13:44 +00:00
|
|
|
'scheduled_at' => 'datetime',
|
|
|
|
|
'published_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 23:08:16 +00:00
|
|
|
/**
|
|
|
|
|
* Get media items as a collection of MediaItem DTOs.
|
|
|
|
|
*
|
|
|
|
|
* @return Collection<int, MediaItem>
|
|
|
|
|
*/
|
|
|
|
|
protected function mediaItems(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
|
|
|
|
get: fn () => collect($this->media ?? [])->map(fn (array $item) => MediaItem::fromArray($item)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
public function workspace(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Workspace::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postPlatforms(): HasMany
|
|
|
|
|
{
|
feat: media gallery picker, custom emoji picker, preview tabs, real platform logos
- gallery: extract /assets tabs (uploads, Unsplash, Giphy) into shared
GalleryBrowser used by both /assets and a new MediaPickerDialog inside the
post editor; add JSON search endpoint for workspace assets with tests
- emoji: replace broken emoji-picker-element web component with a custom
EmojiPicker (full Unicode set, search, categories, recently-used,
light/dark, i18n)
- preview tab: platform selector pills, variant tabs (data-driven from
content_types map) so the user can switch Feed/Reel/Story etc. and have
it autosave through the same handler ScheduleTab uses
- platform logos: shared usePlatformLogo composable (logo + label + content
types); replaces inline maps across 5 components, fixes
instagram-facebook falling back to default.png
- tooltips: hover details (display_name · @username + platform label) on
platform avatars across editor, posts list and calendar
- settings cards: show ` · @username` in the title bar so multiple accounts
on the same network are distinguishable
- routes: drop the throttle:6,1 group middleware on social connect routes
(was 429ing legitimate OAuth retries) and rely on the default limiter
2026-05-01 17:53:49 +00:00
|
|
|
return $this->hasMany(PostPlatform::class)->orderBy('id');
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 23:08:16 +00:00
|
|
|
public function comments(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(PostComment::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 18:18:35 +00:00
|
|
|
public function labels(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(WorkspaceLabel::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
public function scopeScheduled(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', PostStatus::Scheduled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeDue(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->scheduled()->where('scheduled_at', '<=', now());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeDraft(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', PostStatus::Draft);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopePublished(Builder $query): Builder
|
|
|
|
|
{
|
2026-05-04 01:11:58 +00:00
|
|
|
return $query->whereIn('status', [PostStatus::Published, PostStatus::PartiallyPublished]);
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeFailed(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', PostStatus::Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsPublishing(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update(['status' => PostStatus::Publishing]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsPublished(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => PostStatus::Published,
|
|
|
|
|
'published_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 17:24:39 +00:00
|
|
|
public function markAsPartiallyPublished(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => PostStatus::PartiallyPublished,
|
|
|
|
|
'published_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
public function markAsFailed(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update(['status' => PostStatus::Failed]);
|
|
|
|
|
}
|
2026-05-04 18:17:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MediaTypes accepted by this post — the intersection of what every
|
|
|
|
|
* enabled platform allows. With no platform enabled, accept anything.
|
|
|
|
|
*
|
|
|
|
|
* @return array<Type>
|
|
|
|
|
*/
|
|
|
|
|
public function allowedMediaTypes(): array
|
|
|
|
|
{
|
|
|
|
|
$platforms = $this->postPlatforms()
|
|
|
|
|
->where('enabled', true)
|
|
|
|
|
->with('socialAccount')
|
|
|
|
|
->get()
|
|
|
|
|
->pluck('socialAccount.platform')
|
|
|
|
|
->filter();
|
|
|
|
|
|
2026-06-28 20:28:05 +00:00
|
|
|
return self::allowedMediaTypesFor($platforms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-28 23:37:04 +00:00
|
|
|
* Media types acceptable across a set of platforms (intersection; empty = all).
|
2026-06-28 20:28:05 +00:00
|
|
|
*
|
|
|
|
|
* @param Collection<int, Platform> $platforms
|
|
|
|
|
* @return array<Type>
|
|
|
|
|
*/
|
|
|
|
|
public static function allowedMediaTypesFor(Collection $platforms): array
|
|
|
|
|
{
|
2026-05-04 18:17:48 +00:00
|
|
|
if ($platforms->isEmpty()) {
|
|
|
|
|
return Type::cases();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sets = $platforms
|
2026-06-28 20:28:05 +00:00
|
|
|
->map(fn (Platform $platform) => array_map(fn ($type) => $type->value, $platform->allowedMediaTypes()))
|
2026-05-04 18:17:48 +00:00
|
|
|
->all();
|
|
|
|
|
|
|
|
|
|
return array_map(
|
|
|
|
|
Type::from(...),
|
|
|
|
|
array_values(array_intersect(...$sets)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Append items to the JSON `media` column under a row lock so
|
|
|
|
|
* concurrent writers don't overwrite each other's appends.
|
|
|
|
|
*
|
|
|
|
|
* @param array<int, array<string, mixed>> $items
|
|
|
|
|
*/
|
|
|
|
|
public function appendMedia(array $items): void
|
|
|
|
|
{
|
|
|
|
|
DB::transaction(function () use ($items): void {
|
|
|
|
|
$fresh = static::whereKey($this->id)->lockForUpdate()->first();
|
|
|
|
|
$fresh->update([
|
|
|
|
|
'media' => collect($fresh->media ?? [])->concat($items)->all(),
|
|
|
|
|
]);
|
|
|
|
|
$this->setRawAttributes($fresh->getAttributes(), true);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|