Completed
Push — device_ip ( 1d928b...ddfcff )
by Tony
03:21 queued 11s
created

HomeController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Dashboard;
6
use Dingo\Api\Http;
7
use Dingo\Api\Routing\Helpers;
8
use Illuminate\Http\Request;
9
use JWTAuth;
10
11
class HomeController extends Controller
12
{
13
    use Helpers;
14
15
    public function __construct(Request $request) {
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
        $this->middleware('auth');
17
    }
18
19
    public function redirect(Request $request)
20
    {
21
        $dashboard = Dashboard::where('user_id', $request->user()->user_id)->first();
22
        if (empty($dashboard->dashboard_id))
23
        {
24
            $dashboard = new dashboard;
25
            $dashboard->dashboard_name = 'Default';
26
            $dashboard->access         = 0;
27
            $request->user()->dashboards()->save($dashboard);
28
        }
29
        return redirect()->route('dashboard.show', ['id' => $dashboard->dashboard_id]);
30
    }
31
32
    public function index(Request $request) {
33
        $dashboards = $this->api->be(auth()->user())->get('/api/dashboard');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        return view('home', ['dashboards' => $dashboards, 'request' => $request]);
35
    }
36
37
    public function show(Request $request)
38
    {
39
        $token      = JWTAuth::fromUser(auth()->user());
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        $dashboards = $this->api->be(auth()->user())->get('/api/dashboard');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        if (Dashboard::find($request->route('dashboard_id')))
42
        {
43
            $dash    = $this->api->be(auth()->user())->get('/api/dashboard/'.$request->route('dashboard_id'));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
            $widgets = $this->api->be(auth()->user())->get('/api/widget');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
        }
46
        else {
47
            return redirect()->route('home');
48
        }
49
        return view('home', ['dashboards' => $dashboards, 'request' => $request, 'dash_widgets' => $dash['widgets'], 'token' => $token, 'dash_details' => $dash['dashboard'], 'widgets' => $widgets]);
50
    }
51
52
    public function about() {
53
        $versions = $this->api->be(auth()->user())->get('/api/info');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $stats    = $this->api->be(auth()->user())->get('/api/stats');
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        return view('general.about', ['versions' => $versions, 'stats' => $stats]);
56
    }
57
}
58