mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 01:04:03 +00:00
New feature allowing company owners/admins to invite users by email with a specific company-scoped role. Database: - New company_invitations table (company_id, email, role_id, token, status, invited_by, expires_at) Backend: - CompanyInvitation model with pending/forUser scopes - InvitationService: invite, accept, decline, getPendingForUser - CompanyInvitationMail with markdown email template - InvitationController (company-scoped): list, send, cancel invitations - InvitationResponseController (user-scoped): pending, accept, decline - BootstrapController returns pending_invitations in response - CompanyMiddleware handles zero-company users gracefully Tests: 9 feature tests covering invite, accept, decline, cancel, expire, duplicate prevention, and bootstrap integration.
32 lines
1.0 KiB
PHP
32 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class CompanyInvitationResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'company_id' => $this->company_id,
|
|
'email' => $this->email,
|
|
'token' => $this->token,
|
|
'status' => $this->status,
|
|
'expires_at' => $this->expires_at,
|
|
'created_at' => $this->created_at,
|
|
'company' => $this->when($this->relationLoaded('company'), function () {
|
|
return new CompanyResource($this->company);
|
|
}),
|
|
'role' => $this->when($this->relationLoaded('role'), function () {
|
|
return new RoleResource($this->role);
|
|
}),
|
|
'invited_by' => $this->when($this->relationLoaded('invitedBy'), function () {
|
|
return new UserResource($this->invitedBy);
|
|
}),
|
|
];
|
|
}
|
|
}
|