initial commit
This commit is contained in:
105
app/Http/Controllers/ClientController.php
Normal file
105
app/Http/Controllers/ClientController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ClientStatus;
|
||||
use App\Models\Client;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$clients = Client::withCount(['invoices', 'events', 'contentBriefs'])
|
||||
->latest()
|
||||
->paginate(12);
|
||||
|
||||
return view('clients.index', compact('clients'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$statuses = ClientStatus::cases();
|
||||
return view('clients.create', compact('statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'nullable|email|unique:clients,email',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'company' => 'nullable|string|max:255',
|
||||
'ig_handle' => 'nullable|string|max:100',
|
||||
'tiktok_handle' => 'nullable|string|max:100',
|
||||
'youtube_handle' => 'nullable|string|max:100',
|
||||
'address_line1' => 'nullable|string|max:255',
|
||||
'address_line2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'state' => 'nullable|string|max:100',
|
||||
'postal_code' => 'nullable|string|max:20',
|
||||
'country' => 'nullable|string|max:100',
|
||||
'status' => 'required|in:active,inactive,prospect',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
Client::create($validated);
|
||||
|
||||
return redirect()->route('clients.index')
|
||||
->with('success', '🐱 Client added successfully!');
|
||||
}
|
||||
|
||||
public function show(Client $client): View
|
||||
{
|
||||
$client->load(['events' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['invoices' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['contentBriefs' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['mediaFiles' => fn ($q) => $q->latest()->limit(10)]);
|
||||
|
||||
return view('clients.show', compact('client'));
|
||||
}
|
||||
|
||||
public function edit(Client $client): View
|
||||
{
|
||||
$statuses = ClientStatus::cases();
|
||||
return view('clients.edit', compact('client', 'statuses'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Client $client): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'nullable|email|unique:clients,email,' . $client->id,
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'company' => 'nullable|string|max:255',
|
||||
'ig_handle' => 'nullable|string|max:100',
|
||||
'tiktok_handle' => 'nullable|string|max:100',
|
||||
'youtube_handle' => 'nullable|string|max:100',
|
||||
'address_line1' => 'nullable|string|max:255',
|
||||
'address_line2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'state' => 'nullable|string|max:100',
|
||||
'postal_code' => 'nullable|string|max:20',
|
||||
'country' => 'nullable|string|max:100',
|
||||
'status' => 'required|in:active,inactive,prospect',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$client->update($validated);
|
||||
|
||||
return redirect()->route('clients.show', $client)
|
||||
->with('success', '🐱 Client updated successfully!');
|
||||
}
|
||||
|
||||
public function destroy(Client $client): RedirectResponse
|
||||
{
|
||||
$client->delete();
|
||||
|
||||
return redirect()->route('clients.index')
|
||||
->with('success', '🐱 Client removed.');
|
||||
}
|
||||
}
|
||||
121
app/Http/Controllers/ContentBriefController.php
Normal file
121
app/Http/Controllers/ContentBriefController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ContentStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\ContentBrief;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ContentBriefController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
|
||||
$columns = collect(ContentStatus::cases())->map(fn (ContentStatus $status) => [
|
||||
'status' => $status,
|
||||
'items' => ContentBrief::with('client')
|
||||
->where('status', $status->value)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('target_date')
|
||||
->get(),
|
||||
]);
|
||||
|
||||
return view('content.index', compact('columns', 'clients'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = ContentStatus::cases();
|
||||
return view('content.create', compact('clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'content_type' => 'required|string|max:50',
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'hook' => 'nullable|string',
|
||||
'body' => 'nullable|string',
|
||||
'cta' => 'nullable|string',
|
||||
'script' => 'nullable|string',
|
||||
'caption' => 'nullable|string',
|
||||
'hashtags' => 'nullable|string',
|
||||
'target_date' => 'nullable|date',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
ContentBrief::create($validated);
|
||||
|
||||
return redirect()->route('content.index')
|
||||
->with('success', '🎬 Content brief created!');
|
||||
}
|
||||
|
||||
public function show(ContentBrief $contentBrief): View
|
||||
{
|
||||
$contentBrief->load('client');
|
||||
return view('content.show', ['brief' => $contentBrief]);
|
||||
}
|
||||
|
||||
public function edit(ContentBrief $contentBrief): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = ContentStatus::cases();
|
||||
$contentBrief->load('client');
|
||||
return view('content.edit', ['brief' => $contentBrief, 'clients' => $clients, 'statuses' => $statuses]);
|
||||
}
|
||||
|
||||
public function update(Request $request, ContentBrief $contentBrief): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'content_type' => 'required|string|max:50',
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'hook' => 'nullable|string',
|
||||
'body' => 'nullable|string',
|
||||
'cta' => 'nullable|string',
|
||||
'script' => 'nullable|string',
|
||||
'caption' => 'nullable|string',
|
||||
'hashtags' => 'nullable|string',
|
||||
'target_date' => 'nullable|date',
|
||||
'posted_date' => 'nullable|date',
|
||||
'posted_url' => 'nullable|url',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$contentBrief->update($validated);
|
||||
|
||||
return redirect()->route('content.show', $contentBrief)
|
||||
->with('success', '🎬 Content brief updated!');
|
||||
}
|
||||
|
||||
public function destroy(ContentBrief $contentBrief): RedirectResponse
|
||||
{
|
||||
$contentBrief->delete();
|
||||
return redirect()->route('content.index')->with('success', 'Content brief removed.');
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, ContentBrief $contentBrief): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$contentBrief->update($validated);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
25
app/Http/Controllers/DashboardController.php
Normal file
25
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\DashboardService;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DashboardService $dashboardService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
return view('dashboard', [
|
||||
'stats' => $this->dashboardService->getStats(),
|
||||
'todayActivities' => $this->dashboardService->getTodayActivities(),
|
||||
'latestInvoices' => $this->dashboardService->getLatestInvoices(),
|
||||
'socialStats' => $this->dashboardService->getSocialStats(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
129
app/Http/Controllers/EventController.php
Normal file
129
app/Http/Controllers/EventController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$events = Event::with('client')->orderBy('start_time')->get();
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
|
||||
// Format for FullCalendar
|
||||
$calendarEvents = $events->map(fn (Event $e) => [
|
||||
'id' => $e->id,
|
||||
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
||||
'start' => $e->start_time->toIso8601String(),
|
||||
'end' => $e->end_time?->toIso8601String(),
|
||||
'backgroundColor' => $e->color,
|
||||
'borderColor' => $e->color,
|
||||
'extendedProps' => [
|
||||
'status' => $e->status->value,
|
||||
'client' => $e->client?->name,
|
||||
'type' => $e->event_type,
|
||||
'priority' => $e->is_priority,
|
||||
],
|
||||
]);
|
||||
|
||||
return view('schedule.index', compact('events', 'clients', 'calendarEvents'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'event_type' => 'required|in:task,meeting,deadline,posting',
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date|after:start_time',
|
||||
'location' => 'nullable|string|max:255',
|
||||
'is_priority' => 'boolean',
|
||||
'is_all_day' => 'boolean',
|
||||
'color' => 'nullable|string|max:20',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['is_priority'] = $request->boolean('is_priority');
|
||||
$validated['is_all_day'] = $request->boolean('is_all_day');
|
||||
|
||||
Event::create($validated);
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event scheduled!');
|
||||
}
|
||||
|
||||
public function update(Request $request, Event $event): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'event_type' => 'required|in:task,meeting,deadline,posting',
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date',
|
||||
'location' => 'nullable|string|max:255',
|
||||
'is_priority' => 'boolean',
|
||||
'status' => 'required|in:pending,in_progress,completed,cancelled',
|
||||
'color' => 'nullable|string|max:20',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['is_priority'] = $request->boolean('is_priority');
|
||||
$event->update($validated);
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event updated!');
|
||||
}
|
||||
|
||||
public function updateDates(Request $request, Event $event): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'start_time' => 'required|date',
|
||||
'end_time' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$event->update($validated);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function destroy(Event $event): RedirectResponse
|
||||
{
|
||||
$event->delete();
|
||||
|
||||
return redirect()->route('schedule.index')
|
||||
->with('success', '🐾 Event removed.');
|
||||
}
|
||||
|
||||
public function apiList(): JsonResponse
|
||||
{
|
||||
$events = Event::with('client')->get()->map(fn (Event $e) => [
|
||||
'id' => $e->id,
|
||||
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
|
||||
'start' => $e->start_time->toIso8601String(),
|
||||
'end' => $e->end_time?->toIso8601String(),
|
||||
'backgroundColor' => $e->color,
|
||||
'borderColor' => $e->color,
|
||||
'allDay' => $e->is_all_day,
|
||||
'extendedProps' => [
|
||||
'status' => $e->status->value,
|
||||
'client' => $e->client?->name,
|
||||
'type' => $e->event_type,
|
||||
'priority' => $e->is_priority,
|
||||
],
|
||||
]);
|
||||
|
||||
return response()->json($events);
|
||||
}
|
||||
}
|
||||
119
app/Http/Controllers/InvoiceController.php
Normal file
119
app/Http/Controllers/InvoiceController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\InvoiceService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvoiceService $invoiceService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
$invoices = Invoice::with('client')->latest()->paginate(15);
|
||||
return view('invoices.index', compact('invoices'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
return view('invoices.create', compact('clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'tax_rate' => 'required|numeric|min:0|max:100',
|
||||
'currency' => 'required|string|max:10',
|
||||
'issue_date' => 'required|date',
|
||||
'due_date' => 'required|date|after_or_equal:issue_date',
|
||||
'notes' => 'nullable|string',
|
||||
'bank_name' => 'nullable|string|max:100',
|
||||
'bank_account' => 'nullable|string|max:50',
|
||||
'bank_holder' => 'nullable|string|max:100',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.description' => 'required|string',
|
||||
'items.*.quantity' => 'required|integer|min:1',
|
||||
'items.*.unit_price' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$items = $validated['items'];
|
||||
unset($validated['items']);
|
||||
$validated['status'] = InvoiceStatus::Draft->value;
|
||||
|
||||
$invoice = $this->invoiceService->create($validated, $items);
|
||||
|
||||
return redirect()->route('invoices.show', $invoice)
|
||||
->with('success', '🧾 Invoice created!');
|
||||
}
|
||||
|
||||
public function show(Invoice $invoice): View
|
||||
{
|
||||
$invoice->load('client', 'items');
|
||||
return view('invoices.show', compact('invoice'));
|
||||
}
|
||||
|
||||
public function edit(Invoice $invoice): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
$invoice->load('client', 'items');
|
||||
return view('invoices.edit', compact('invoice', 'clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Invoice $invoice): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'tax_rate' => 'required|numeric|min:0|max:100',
|
||||
'status' => 'required|in:draft,sent,paid,overdue,cancelled',
|
||||
'issue_date' => 'required|date',
|
||||
'due_date' => 'required|date',
|
||||
'paid_date' => 'nullable|date',
|
||||
'notes' => 'nullable|string',
|
||||
'bank_name' => 'nullable|string|max:100',
|
||||
'bank_account' => 'nullable|string|max:50',
|
||||
'bank_holder' => 'nullable|string|max:100',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.description' => 'required|string',
|
||||
'items.*.quantity' => 'required|integer|min:1',
|
||||
'items.*.unit_price' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$items = $validated['items'];
|
||||
unset($validated['items']);
|
||||
|
||||
$this->invoiceService->update($invoice, $validated, $items);
|
||||
|
||||
return redirect()->route('invoices.show', $invoice)
|
||||
->with('success', '🧾 Invoice updated!');
|
||||
}
|
||||
|
||||
public function destroy(Invoice $invoice): RedirectResponse
|
||||
{
|
||||
$invoice->delete();
|
||||
return redirect()->route('invoices.index')->with('success', 'Invoice deleted.');
|
||||
}
|
||||
|
||||
public function pdf(Invoice $invoice): Response
|
||||
{
|
||||
return $this->invoiceService->generatePdf($invoice);
|
||||
}
|
||||
}
|
||||
77
app/Http/Controllers/MediaFileController.php
Normal file
77
app/Http/Controllers/MediaFileController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\MediaFile;
|
||||
use App\Services\FileService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class MediaFileController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly FileService $fileService
|
||||
) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$folder = $request->get('folder', 'all');
|
||||
$client = $request->get('client_id');
|
||||
$clients = Client::orderBy('name')->get();
|
||||
|
||||
$query = MediaFile::with('client')->latest();
|
||||
|
||||
if ($folder !== 'all') {
|
||||
$query->where('folder', $folder);
|
||||
}
|
||||
|
||||
if ($client) {
|
||||
$query->where('client_id', $client);
|
||||
}
|
||||
|
||||
$files = $query->paginate(20)->withQueryString();
|
||||
$folders = MediaFile::select('folder')->distinct()->pluck('folder');
|
||||
|
||||
return view('files.index', compact('files', 'folders', 'folder', 'clients'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'file' => 'required|file|max:51200', // 50 MB
|
||||
'folder' => 'required|string|max:100',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
]);
|
||||
|
||||
$this->fileService->uploadAsset(
|
||||
$request->file('file'),
|
||||
$request->input('folder'),
|
||||
$request->input('client_id')
|
||||
);
|
||||
|
||||
return back()->with('success', '📁 File uploaded successfully!');
|
||||
}
|
||||
|
||||
public function serve(MediaFile $mediaFile): StreamedResponse
|
||||
{
|
||||
abort_unless(Storage::disk($mediaFile->disk)->exists($mediaFile->path), 404);
|
||||
|
||||
return Storage::disk($mediaFile->disk)->response(
|
||||
$mediaFile->path,
|
||||
$mediaFile->original_name,
|
||||
['Content-Type' => $mediaFile->mime_type]
|
||||
);
|
||||
}
|
||||
|
||||
public function destroy(MediaFile $mediaFile): RedirectResponse
|
||||
{
|
||||
$this->fileService->delete($mediaFile);
|
||||
return back()->with('success', 'File deleted.');
|
||||
}
|
||||
}
|
||||
93
app/Http/Controllers/RateCardController.php
Normal file
93
app/Http/Controllers/RateCardController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\RateCard;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RateCardController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get();
|
||||
return view('rate-cards.index', compact('rateCards'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('rate-cards.create');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = true;
|
||||
|
||||
RateCard::create($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card entry added!');
|
||||
}
|
||||
|
||||
public function edit(RateCard $rateCard): View
|
||||
{
|
||||
return view('rate-cards.edit', compact('rateCard'));
|
||||
}
|
||||
|
||||
public function update(Request $request, RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = $request->boolean('is_active');
|
||||
|
||||
$rateCard->update($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card updated!');
|
||||
}
|
||||
|
||||
public function destroy(RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$rateCard->delete();
|
||||
return redirect()->route('rate-cards.index')->with('success', 'Entry removed.');
|
||||
}
|
||||
|
||||
public function public(): View
|
||||
{
|
||||
$rateCards = RateCard::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('platform')
|
||||
->get()
|
||||
->groupBy('platform');
|
||||
|
||||
return view('rate-cards.public', compact('rateCards'));
|
||||
}
|
||||
}
|
||||
61
app/Http/Controllers/SocialHubController.php
Normal file
61
app/Http/Controllers/SocialHubController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ContentBrief;
|
||||
use App\Models\SocialStat;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SocialHubController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
// Get latest stats per platform
|
||||
$stats = collect(['instagram', 'tiktok', 'youtube'])->map(fn (string $platform) => [
|
||||
'platform' => $platform,
|
||||
'latest' => SocialStat::where('platform', $platform)
|
||||
->orderByDesc('recorded_date')
|
||||
->first(),
|
||||
'history' => SocialStat::where('platform', $platform)
|
||||
->orderByDesc('recorded_date')
|
||||
->limit(7)
|
||||
->get(),
|
||||
]);
|
||||
|
||||
// Posting frequency - count by platform per month
|
||||
$postingFrequency = ContentBrief::where('status', 'posted')
|
||||
->selectRaw("platform, strftime('%Y-%m', posted_date) as month, count(*) as count")
|
||||
->whereNotNull('posted_date')
|
||||
->groupBy('platform', 'month')
|
||||
->orderBy('month')
|
||||
->limit(30)
|
||||
->get();
|
||||
|
||||
return view('social-hub.index', compact('stats', 'postingFrequency'));
|
||||
}
|
||||
|
||||
public function storeStats(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'handle' => 'nullable|string|max:100',
|
||||
'followers' => 'required|integer|min:0',
|
||||
'following' => 'nullable|integer|min:0',
|
||||
'posts_count' => 'nullable|integer|min:0',
|
||||
'engagement_rate' => 'nullable|numeric|min:0|max:100',
|
||||
'avg_views' => 'nullable|integer|min:0',
|
||||
'avg_likes' => 'nullable|integer|min:0',
|
||||
'avg_comments' => 'nullable|integer|min:0',
|
||||
]);
|
||||
|
||||
$validated['recorded_date'] = today()->toDateString();
|
||||
|
||||
SocialStat::create($validated);
|
||||
|
||||
return back()->with('success', '📊 Stats updated!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user