1 | <?php |
||
9 | class AdminUserDataTable extends DataTable |
||
10 | { |
||
11 | /** |
||
12 | * Build DataTable class. |
||
13 | * |
||
14 | * @return \Yajra\Datatables\Engines\BaseEngine |
||
15 | */ |
||
16 | public function dataTable() |
||
28 | |||
29 | /** |
||
30 | * Get the query object to be processed by dataTables. |
||
31 | * |
||
32 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
||
33 | */ |
||
34 | public function query() |
||
40 | |||
41 | /** |
||
42 | * Optional method if you want to use html builder. |
||
43 | * |
||
44 | * @return \Yajra\Datatables\Html\Builder |
||
45 | */ |
||
46 | public function html() |
||
53 | |||
54 | /** |
||
55 | * Get columns. |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | protected function getColumns() |
||
69 | |||
70 | /** |
||
71 | * Get the "avatar" column data. |
||
72 | * |
||
73 | * @param AdminUser $user |
||
74 | * @return mixed |
||
75 | */ |
||
76 | protected function getAvatarColumnData($user) |
||
84 | |||
85 | /** |
||
86 | * Get the "action" column data. |
||
87 | * |
||
88 | * @param AdminUser $user |
||
89 | * @return mixed |
||
90 | */ |
||
91 | protected function getActionColumnData($user) |
||
107 | |||
108 | /** |
||
109 | * Get the default builder parameters. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | protected function getBuilderParameters() |
||
119 | } |
||
120 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: