Issues (364)

app/Tables/Builders/UserTable.php (3 issues)

1
<?php
2
3
namespace App\Tables\Builders;
4
5
use App\Models\User;
6
use Illuminate\Database\Eloquent\Builder;
7
use LaravelEnso\Tables\Contracts\Table;
8
9
class UserTable implements Table
10
{
11
    protected const TemplatePath = __DIR__.'/../Templates/users.json';
12
13
    protected $query;
14
15
    public function query(): Builder
16
    {
17
        $role = \Auth::user()->role_id;
0 ignored issues
show
Accessing role_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
18
        $userId = \Auth::user()->id;
0 ignored issues
show
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
19
20
        if (in_array($role, [1, 2])) {
21
            $user = User::with('avatar:id,user_id')->selectRaw('
22
                users.id, user_groups.name as "group", people.name, people.appellative,
23
                people.phone, users.email, roles.name as role, users.is_active,
24
                users.created_at, users.person_id
25
            ')->join('people', 'users.person_id', '=', 'people.id')
26
                ->join('user_groups', 'users.group_id', '=', 'user_groups.id')
27
                ->join('roles', 'users.role_id', '=', 'roles.id');
28
        } else {
29
            $user = User::with('avatar:id,user_id')->selectRaw('
30
                users.id, user_groups.name as "group", people.name, people.appellative,
31
                people.phone, users.email, roles.name as role, users.is_active,
32
                users.created_at, users.person_id
33
            ')->join('people', 'users.person_id', '=', 'people.id')
34
                ->join('user_groups', 'users.group_id', '=', 'user_groups.id')
35
                ->join('roles', 'users.role_id', '=', 'roles.id')->where('users.id', $userId);
36
        }
37
38
        return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
41
    public function templatePath(): string
42
    {
43
        return static::TemplatePath;
44
    }
45
}
46