You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+139Lines changed: 139 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -268,6 +268,145 @@ public function setTableDataId($attribute, $value) : ?string;
268
268
public function setTableDataAttributes($attribute, $value) : array;
269
269
```
270
270
271
+
### Components
272
+
273
+
Along with being able to provide a view to a column, you can use pre-defined components that are built into the package. These are good for when you want to add actions to a column.
274
+
275
+
**Note:** By design using the components() method on a column will disable all other functionality (i.e. searching/sorting etc.).
276
+
277
+
#### Defining Components for a Column
278
+
279
+
```php
280
+
Column::make('Actions')
281
+
->components([
282
+
Link::make('Edit'),
283
+
Link::make('Delete'),
284
+
])
285
+
````
286
+
287
+
or
288
+
289
+
```php
290
+
Column::make('Actions')
291
+
->addComponent(Link::make('Edit'))
292
+
->addComponent(Link::make('Delete'))
293
+
````
294
+
295
+
If you would like to all the components for a given row, you may pass a callback as the second parameter of the `components()` method:
296
+
297
+
```php
298
+
Column::make('Actions')
299
+
->components([
300
+
Link::make('Edit'),
301
+
Link::make('Delete'),
302
+
], function($model) {
303
+
// Hide the actions for model id 1
304
+
return $model->id === 1;
305
+
})
306
+
````
307
+
308
+
Building on that, if you would like to pass a custom message to that column when hiding the components for this row, you may pass another callback as the third parameter:
309
+
310
+
```php
311
+
Column::make('Actions')
312
+
->components([
313
+
Link::make('Edit'),
314
+
Link::make('Delete'),
315
+
], function($model) {
316
+
// Hide the actions for model id 1
317
+
return $model->id === 1;
318
+
}, function($model) {
319
+
return __('You can not alter role ' . $model->name . '.');
320
+
})
321
+
````
322
+
323
+
#### Methods
324
+
325
+
Of course two links that don't do anything would be useless, here are a list of methods to be used for the built in components.
326
+
327
+
#### Inherited by all components
328
+
| Method | Usage |
329
+
| -------- | ----- |
330
+
| setAttribute($attribute, $value) | Set an attribute on the component |
331
+
| setAttributes(array $attributes = []) | Set multiple attributes at once |
332
+
| getAttributes() | Get the array of available attributes |
333
+
| setOption($option, $value) | Set an option on the component |
334
+
| setOptions(array $options = []) | Set multiple options at once |
335
+
| getOptions() | Get the array of available options |
336
+
| hideIf($condition) | Hide this component if true |
337
+
| hide() | Hide this component forever |
338
+
| isHidden() | This component is currently hidden |
339
+
340
+
By default all components have access to the `$attributes` and `$options` arrays.
341
+
342
+
#### Link Component
343
+
344
+
| Method | Usage | Type |
345
+
| -------- | ----- | ---- |
346
+
| text($text) | Set the text of the link | string/false |
347
+
| class($class) | Set the html class on the link | string |
348
+
| id($id) | Set the id of the link | string |
349
+
| icon($icon) | Set the icon of the link (font awesome) | string |
350
+
| href(function($model){}) | Set the href of the link | string/callback |
351
+
| view($view) | The view to render for the component | string |
352
+
353
+
#### Button Component
354
+
355
+
| Method | Usage | Type |
356
+
| -------- | ----- | ---- |
357
+
| text($text) | Set the text of the button | string/false |
358
+
| class($class) | Set the html class on the button | string |
359
+
| id($id) | Set the id of the button | string |
360
+
| icon($icon) | Set the icon of the button (font awesome) | string |
361
+
| view($view) | The view to render for the component | string |
362
+
363
+
#### Example
364
+
365
+
This example comes from the upcoming release of my popular [Laravel Boilerplate Project](http://laravel-boilerplate.com). Here we render the roles table in the admin panel.
366
+
367
+
This example uses searching, sorting, relationships, custom attributes, counted relationships, and components:
0 commit comments