2026-03-29 22:24:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\App;
|
|
|
|
|
|
2026-04-17 02:05:51 +00:00
|
|
|
use App\Actions\Ai\AutofillBrand;
|
2026-03-29 22:24:28 +00:00
|
|
|
use App\Actions\Workspace\CreateWorkspace;
|
|
|
|
|
use App\Actions\Workspace\DeleteWorkspace;
|
refactor: organize middleware/requests into App/ subdirs, add Resources, fix auth routes
- Move middleware to App/ subdir (HandleInertiaRequests, HandleAppearance,
EnsureSubscribed, EnsureUserSetupIsComplete) matching Sendkit pattern
- Move all Form Requests into organized subdirs (App/Post, App/Workspace,
App/Media, App/Invite, App/Settings, App/Auth)
- Create AuthUserResource and AuthWorkspaceResource for HandleInertiaRequests
shared data (role inside currentWorkspace, matching Sendkit pattern)
- Split auth.php into 3 route groups (no middleware, guest, auth) matching
Sendkit pattern exactly
- Fix UserFactory to include all nullable attributes (current_workspace_id,
stripe_id, pm_type, pm_last_four, trial_ends_at)
- Fix SocialAccountResource (display_name not name)
- Update frontend for new auth prop structure
- 702 tests passing (2 pre-existing Mastodon failures)
2026-03-30 00:13:30 +00:00
|
|
|
use App\Http\Requests\App\Workspace\StoreWorkspaceRequest;
|
|
|
|
|
use App\Http\Requests\App\Workspace\UpdateWorkspaceRequest;
|
2026-03-29 22:24:28 +00:00
|
|
|
use App\Models\Workspace;
|
2026-04-17 02:05:51 +00:00
|
|
|
use App\Services\Brand\LogoAttacher;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
2026-04-17 02:05:51 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Inertia\Response;
|
2026-04-17 02:05:51 +00:00
|
|
|
use RuntimeException;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
|
|
|
|
use Throwable;
|
2026-03-29 22:24:28 +00:00
|
|
|
|
|
|
|
|
class WorkspaceController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
|
|
|
|
$workspaces = $user->workspaces()
|
refactor: auth split layout, subscribe redesign, onboarding, i18n, cookie locale
Auth pages:
- Create AuthSplitLayout with animated feature slides (6 slides, 3 languages)
- All auth pages use split layout (form left, visual right)
- Add show/hide password toggle with tooltip on Register
- Legal footer only shown on Register via showLegal prop
Subscribe page:
- Redesign to match auth card pattern (centered, clean)
- Platform icons, feature checklist, dynamic trial days (trialDays - 1)
- Add "Switch workspace" link
- Full i18n (en, es, pt-BR)
Onboarding:
- Rename URLs: step1 -> role, step2 -> connect
- Add enforceStep() to prevent skipping/going back steps
- Redirect /onboarding to /onboarding/role
- Redesign Step2 with AuthSplitLayout and compact platform list
- 21 tests covering all step enforcement scenarios
Workspaces page:
- Redesign with AuthSplitLayout (list with avatars, current badge)
Language system:
- Move locale from DB to cookie (forever, unencrypted, session.domain)
- Create SetLocale middleware (sets cookie if missing, validates against config)
- Rename lang/pt-br to lang/pt-BR
- Add dayjs es locale
Other:
- Copy utils.ts from sendkit (formatNumber, formatMoney, copyToClipboard)
- ConfirmDeleteModal with text confirmation (sendkit pattern)
- i18n for ConfirmDeleteModal internal strings (common.php)
- EmptyState component for posts index
- Exact match for "All" posts in sidebar
- Posts breadcrumbs show current status filter
- DialogFooter buttons aligned left
- API Keys page redesign with Table, DropdownMenu, EmptyState
- Extract CreateApiKeyDialog and InviteMemberDialog to components
- Remove API Keys from sidebar
- DropdownMenuItem destructive variant for Remove action
2026-03-30 14:53:42 +00:00
|
|
|
->with('media')
|
2026-03-29 22:24:28 +00:00
|
|
|
->withCount(['socialAccounts', 'posts'])
|
|
|
|
|
->latest()
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return Inertia::render('workspaces/Index', [
|
|
|
|
|
'workspaces' => $workspaces,
|
|
|
|
|
'currentWorkspaceId' => $user->current_workspace_id,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create(Request $request): Response|RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
2026-04-14 21:22:36 +00:00
|
|
|
$workspace = $user->currentWorkspace;
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
if ($user->ownedWorkspacesCount() > 0 && ! $user->account?->hasActiveSubscription()) {
|
2026-03-29 22:24:28 +00:00
|
|
|
return redirect()->route('app.billing.index')
|
|
|
|
|
->with('message', 'Subscribe to create more workspaces.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Inertia::render('workspaces/Create');
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 02:05:51 +00:00
|
|
|
public function autofillBrand(Request $request, AutofillBrand $autofill): JsonResponse
|
2026-03-29 22:24:28 +00:00
|
|
|
{
|
2026-04-17 02:05:51 +00:00
|
|
|
$validated = $request->validate([
|
|
|
|
|
'url' => ['required', 'string', 'max:255'],
|
|
|
|
|
]);
|
2026-03-29 22:24:28 +00:00
|
|
|
|
2026-04-17 02:05:51 +00:00
|
|
|
try {
|
|
|
|
|
$metadata = $autofill(data_get($validated, 'url'));
|
|
|
|
|
} catch (RuntimeException $e) {
|
|
|
|
|
return response()->json(['message' => $e->getMessage()], SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY);
|
2026-03-29 22:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-17 02:05:51 +00:00
|
|
|
return response()->json($metadata->toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(StoreWorkspaceRequest $request, LogoAttacher $logoAttacher): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
$isFirstWorkspace = ! $user->workspaces()->exists();
|
|
|
|
|
|
|
|
|
|
$workspace = CreateWorkspace::execute($user, $validated);
|
|
|
|
|
|
|
|
|
|
if ($logoUrl = data_get($validated, 'logo_url')) {
|
|
|
|
|
try {
|
|
|
|
|
$logoAttacher->attach($workspace, $logoUrl);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
Log::warning('Logo attach failed during workspace creation', [
|
|
|
|
|
'workspace_id' => $workspace->id,
|
|
|
|
|
'logo_url' => $logoUrl,
|
|
|
|
|
'error' => $e->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-29 22:24:28 +00:00
|
|
|
|
2026-04-17 02:05:51 +00:00
|
|
|
return $isFirstWorkspace
|
|
|
|
|
? redirect()->route('app.accounts')->with('success', __('workspaces.create.first_workspace_success'))
|
|
|
|
|
: redirect()->route('app.calendar')->with('success', __('workspaces.create.success'));
|
2026-03-29 22:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function switch(Request $request, Workspace $workspace): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
|
|
|
|
if (! $user->belongsToWorkspace($workspace)) {
|
|
|
|
|
abort(403);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user->switchWorkspace($workspace);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.calendar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function settings(Request $request): Response|RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
$workspace = $user->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('update', $workspace);
|
|
|
|
|
|
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
|
|
|
$members = $workspace->members()
|
|
|
|
|
->get()
|
|
|
|
|
->map(fn ($member) => [
|
|
|
|
|
'id' => $member->id,
|
|
|
|
|
'name' => $member->name,
|
|
|
|
|
'email' => $member->email,
|
|
|
|
|
'role' => $member->pivot->role,
|
2026-04-15 01:22:04 +00:00
|
|
|
'is_owner' => $member->id === $workspace->account?->owner_id,
|
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
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$invitations = $workspace->invites()
|
2026-04-15 01:22:04 +00:00
|
|
|
->select('id', 'email')
|
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
|
|
|
->latest()
|
|
|
|
|
->get();
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
return Inertia::render('settings/Workspace', [
|
|
|
|
|
'workspace' => $workspace,
|
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
|
|
|
'members' => $members,
|
|
|
|
|
'invitations' => $invitations,
|
2026-03-29 22:24:28 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 02:01:08 +00:00
|
|
|
public function uploadLogo(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
$this->authorize('update', $workspace);
|
|
|
|
|
|
|
|
|
|
$request->validate([
|
|
|
|
|
'photo' => ['required', 'image', 'max:2048'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace->clearMediaCollection('logo');
|
|
|
|
|
$workspace->addMedia($request->file('photo'), 'logo');
|
|
|
|
|
$workspace->unsetRelation('media');
|
|
|
|
|
|
|
|
|
|
session()->flash('flash.banner', __('settings.flash.logo_updated'));
|
|
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteLogo(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
$this->authorize('update', $workspace);
|
|
|
|
|
|
|
|
|
|
$workspace->clearMediaCollection('logo');
|
|
|
|
|
$workspace->unsetRelation('media');
|
|
|
|
|
|
|
|
|
|
session()->flash('flash.banner', __('settings.flash.logo_deleted'));
|
|
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
public function updateSettings(UpdateWorkspaceRequest $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
$workspace = $user->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('update', $workspace);
|
|
|
|
|
|
|
|
|
|
$workspace->update($request->validated());
|
|
|
|
|
|
|
|
|
|
session()->flash('flash.banner', __('settings.flash.workspace_updated'));
|
|
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.workspace.settings');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy(Request $request, Workspace $workspace): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$this->authorize('delete', $workspace);
|
|
|
|
|
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
|
|
|
|
|
DeleteWorkspace::execute($user, $workspace);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.workspaces.index')
|
|
|
|
|
->with('success', 'Workspace deleted successfully!');
|
|
|
|
|
}
|
|
|
|
|
}
|