Spaces:
Sleeping
Sleeping
File size: 1,097 Bytes
10dc6f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?php
namespace App\Http\Controllers\Organizer;
use App\Http\Controllers\Controller;
use App\Models\Event;
use App\Models\Order;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index()
{
$user = auth()->user();
$events = $user->events()->withCount('orders')->get();
$totalRevenue = Order::whereIn('event_id', $events->pluck('id'))
->where('status', 'paid')->sum('total');
$totalOrders = Order::whereIn('event_id', $events->pluck('id'))
->where('status', 'paid')->count();
$totalSold = $events->sum(fn ($e) => $e->ticketTiers->sum('sold_count'));
$activeEvents = $events->where('status', 'published')->count();
$recentOrders = Order::whereIn('event_id', $events->pluck('id'))
->with('user', 'event')
->latest()
->take(10)
->get();
return view('organizer.dashboard', compact(
'events', 'totalRevenue', 'totalOrders', 'totalSold', 'activeEvents', 'recentOrders'
));
}
}
|