Issues (172)

app/Tables/Builders/PersonTable.php (2 issues)

1
<?php
2
3
namespace App\Tables\Builders;
4
5
use App\Person;
6
use App\Traits\ConnectionTrait;
7
use Illuminate\Database\Eloquent\Builder;
8
use LaravelEnso\Tables\Contracts\Table;
9
10
class PersonTable extends \LaravelEnso\People\Tables\Builders\PersonTable
11
{
12
    use ConnectionTrait;
13
14
    protected const TemplatePath = __DIR__.'/../Templates/people.json';
15
16
    public function query(): Builder
17
    {
18
        $conn = $this->getConnection();
19
        $db = $this->getDB();
0 ignored issues
show
The assignment to $db is dead and can be removed.
Loading history...
20
21
        return Person::on($conn)->selectRaw('
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Person::on($c...ny_id', 'companies.id') 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...
22
            people.id
23
            , people.title, people.givn, people.surn,  people.appellative, people.email, people.phone,
24
            people.birthday, people.deathday, CASE WHEN users.id is null THEN 0 ELSE 1 END as "user",
25
            companies.name as company, people.created_at
26
        ')->leftJoin('users', 'people.id', '=', 'users.person_id')
27
            ->leftJoin(
28
                'company_person',
29
                fn ($join) => $join
30
                    ->on('people.id', '=', 'company_person.person_id')
31
                    ->where('company_person.is_main', true)
32
            )->leftJoin('companies', 'company_person.company_id', 'companies.id');
33
    }
34
35
    public function templatePath(): string
36
    {
37
        return static::TemplatePath;
38
    }
39
}
40