Completed
Push — master ( de266e...61eb5c )
by Abdelrahman
02:51
created

DashboardController::home()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Backend;
17
18
use DB;
19
use Carbon\Carbon;
20
use Rinvex\Fort\Http\Controllers\AuthorizedController;
21
22
class DashboardController extends AuthorizedController
23
{
24
    /**
25
     * Show the dashboard home.
26
     *
27
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
     */
29
    public function home()
30
    {
31
        $abilityRepository = app('rinvex.fort.ability');
32
        $roleRepository = app('rinvex.fort.role');
33
        $userRepository = app('rinvex.fort.user');
34
35
        // Get recent registered users
36
        $limit = config('rinvex.fort.backend.items_per_dashboard');
37
        $users = $userRepository->orderBy('created_at', 'desc')->limit($limit)->findAll();
38
39
        // Get statistics
40
        $stats = [
41
            'abilities' => $abilityRepository->count(),
42
            'roles' => $roleRepository->count(),
43
            'users' => $userRepository->count(),
44
        ];
45
46
        // Get online users
47
        $onlineInterval = Carbon::now()->subMinutes(config('rinvex.fort.online.interval'));
48
        $persistences   = app('rinvex.fort.persistence')->groupBy(['user_id'])
49
                                             ->with(['user'])
50
                                             ->where('attempt', '=', 0)
51
                                             ->where('updated_at', '>', $onlineInterval)
52
                                             ->get(['user_id', DB::raw('MAX(updated_at) as updated_at')]);
53
54
        return view('rinvex.fort::backend.dashboard.home', compact('users', 'persistences', 'stats'));
55
    }
56
}
57