Passed
Push — task/relative-resources ( 6eadd5...aef1bd )
by Tristan
06:08 queued 13s
created

ApplicantCrudController::setupListOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 28
rs 9.6
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
7
8
/**
9
 * Class ApplicantCrudController
10
 * @package App\Http\Controllers\Admin
11
 * @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
12
 */
13
class ApplicantCrudController extends CrudController
14
{
15
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
16
17
    public function setup()
18
    {
19
        $this->crud->setModel('App\Models\Applicant');
20
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/applicant');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $this->crud->setRoute(/** @scrutinizer ignore-call */ config('backpack.base.route_prefix') . '/applicant');
Loading history...
21
        $this->crud->setEntityNameStrings('applicant', 'applicants');
22
        $this->crud->denyAccess(['update', 'create', 'delete']);
23
        $this->crud->orderBy('id', 'asc');
24
        $this->crud->addButtonFromView('line', 'view_applicant', 'view_applicant', 'end');
25
    }
26
27
    protected function setupListOperation()
28
    {
29
        $this->crud->addColumn([
30
            'name' => 'id',
31
            'type' => 'number',
32
            'label' => 'ID',
33
            'orderable' => true,
34
        ]);
35
36
        $this->crud->addColumn([
37
            'name' => 'user.full_name',
38
            'type' => 'text',
39
            'label' => 'Full Name',
40
            'searchLogic' => function ($query, $column, $searchTerm) {
41
                $query->orWhereHas('user', function ($q) use ($searchTerm) {
42
                    $q->where('first_name', 'ilike', '%'.$searchTerm.'%')
43
                      ->orWhere('last_name', 'ilike', '%'.$searchTerm.'%');
44
                });
45
            }
46
        ]);
47
48
        $this->crud->addColumn([
49
            'name' => 'user.email',
50
            'type' => 'text',
51
            'label' => 'Email',
52
            'searchLogic' => function ($query, $column, $searchTerm) {
53
                $query->orWhereHas('user', function ($q) use ($searchTerm) {
54
                    $q->where('email', 'ilike', '%'.$searchTerm.'%');
55
                });
56
            }
57
        ]);
58
    }
59
}
60