summaryrefslogtreecommitdiff
path: root/artifacts-from-claude/dashboardctrler
blob: 4f4141724d9ed776bcc94f1282ee9c01d8a848c4 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the user dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $user = Auth::user();

        // You can add any additional data preparation here
        // before passing to the view
        
        return view('dashboard');
    }
    
    /**
     * Show activity statistics.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function statistics()
    {
        $user = Auth::user();
        
        $stats = [
            'files' => [
                'count' => $user->files()->count(),
                'size' => $user->files()->sum('size'),
                'recent' => $user->files()->latest()->take(5)->get()
            ],
            'writings' => [
                'count' => $user->writings()->count(),
                'recent' => $user->writings()->latest()->take(5)->get()
            ],
            'storage' => [
                'used' => $user->getStorageUsed(),
                'total' => $user->storage_quota,
                'percent' => min(100, round(($user->getStorageUsed() / max(1, $user->storage_quota)) * 100))
            ]
        ];
        
        return response()->json($stats);
    }
}