Skip to content

Commit 1f95eb3

Browse files
committed
Merge branch 'BCleverly-patch-1' into develop
# Conflicts: # docs/columns/available-methods.md
2 parents b3517a4 + 22b4f62 commit 1f95eb3

File tree

6 files changed

+109
-84
lines changed

6 files changed

+109
-84
lines changed

docs/columns/available-methods.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ To enable sorting you can chain the `sortable` method on your column:
1111

1212
```php
1313
Column::make('Name')
14-
->sortable()
14+
->sortable(),
1515
```
1616

1717
If you would like more control over the sort behavior of a specific column, you may pass a closure:
1818

1919
```php
2020
Column::make(__('Address'))
21-
->sortable(function(Builder $query, string $direction) {
22-
return $query->orderBy()...
23-
})
21+
->sortable(
22+
fn(Builder $query, string $direction) => $query->orderBy()
23+
),
2424
```
2525

2626
### [Multi-column sorting](../sorting/available-methods#setsinglesortingstatus)
@@ -55,16 +55,16 @@ To enable searching you can chain the `searchable` method on your column:
5555

5656
```php
5757
Column::make('Name')
58-
->searchable()
58+
->searchable(),
5959
```
6060

6161
You can override the default search query using a closure:
6262

6363
```php
6464
Column::make('Name')
65-
->searchable(function (Builder $query, $searchTerm) {
66-
$query->orWhere(...);
67-
}),
65+
->searchable(
66+
fn(Builder $query, $searchTerm) => $query->orWhere()
67+
),
6868
```
6969

7070
## Formatting
@@ -79,9 +79,9 @@ If you would like to modify the value of the column, you can chain the `format`
7979

8080
```php
8181
Column::make('Name')
82-
->format(function($value, $row, Column $column) {
83-
return $row->first_name . ' ' . $row->last_name;
84-
})
82+
->format(
83+
fn($value, $row, Column $column) => $row->first_name . ' ' . $row->last_name
84+
),
8585
```
8686

8787
### Rendering HTML
@@ -90,10 +90,10 @@ If you would like to return HTML from the format method you may:
9090

9191
```php
9292
Column::make('Name')
93-
->format(function($value, $row, Column $column) {
94-
return '<strong>'.$row->first_name . ' ' . $row->last_name.'</strong>';
95-
})
96-
->html()
93+
->format(
94+
fn($value, $row, Column $column) => '<strong>'.$row->first_name . ' ' . $row->last_name.'</strong>'
95+
)
96+
->html(),
9797
```
9898

9999
### Using a view
@@ -102,16 +102,16 @@ If you would like to render a view for the cell:
102102

103103
```php
104104
Column::make('Name')
105-
->format(function($value, $row, Column $column) {
106-
return view('my.custom.view')->withValue($value);
107-
})
105+
->format(
106+
fn($value, $row, Column $column) => view('my.custom.view')->withValue($value)
107+
),
108108
```
109109

110110
As a shorthand you can use the following:
111111

112112
```php
113113
Column::make('Name')
114-
->view('my.custom.view')
114+
->view('my.custom.view'),
115115
```
116116

117117
You will have access to `$row`, `$value`, and `$column` from within your view.
@@ -122,29 +122,29 @@ If you have a column that is not associated with a database column, you can chai
122122

123123
```php
124124
Column::make('My one off column')
125-
->label(function($row, Column $column) {
126-
return $this->getSomeOtherValue($row, $column);
127-
})
125+
->label(
126+
fn($row, Column $column) => $this->getSomeOtherValue($row, $column)
127+
),
128128
```
129129

130130
You can return HTML:
131131

132132
```php
133133
Column::make('My one off column')
134-
->label(function($row, Column $column) {
135-
return '<strong>'.$row->this_other_column.'</strong>';
136-
})
137-
->html()
134+
->label(
135+
fn($row, Column $column) => '<strong>'.$row->this_other_column.'</strong>'
136+
)
137+
->html(),
138138
```
139139

140140
You can also return a view:
141141

142142
```php
143143
Column::make('My one off column')
144144
// Note: The view() method is reserved for columns that have a field
145-
->label(function($row, Column $column) {
146-
return view('my.other.view')->withRow($row);
147-
})
145+
->label(
146+
fn($row, Column $column) => view('my.other.view')->withRow($row)
147+
),
148148
```
149149

150150
## Collapsing
@@ -159,7 +159,7 @@ Collapse on tablet:
159159

160160
```php
161161
Column::make('Name')
162-
->collapseOnTablet()
162+
->collapseOnTablet(),
163163
```
164164

165165
The columns will collapse on tablet and mobile.
@@ -168,7 +168,7 @@ Collapse on mobile:
168168

169169
```php
170170
Column::make('Name')
171-
->collapseOnMobile()
171+
->collapseOnMobile(),
172172
```
173173

174174
The column will collapse on mobile only.
@@ -183,7 +183,7 @@ You can customize the name on the pill for the specific column that's being sort
183183

184184
```php
185185
Column::make('Name')
186-
->setSortingPillTitle('Full Name')
186+
->setSortingPillTitle('Full Name'),
187187
```
188188

189189
### Customizing sorting pill directions
@@ -193,7 +193,7 @@ You can customize the directions on the pill for the specific column that's bein
193193
```php
194194
Column::make('Name')
195195
// Instead of Name: A-Z it will say Name: Asc
196-
->setSortingPillDirections('Asc', 'Desc')
196+
->setSortingPillDirections('Asc', 'Desc'),
197197
```
198198

199199
## Misc.
@@ -204,7 +204,7 @@ If you need the access the relationships on the model from a format call or some
204204

205205
```php
206206
Column::make('Address', 'address.address')
207-
->eagerLoadRelations() // Adds with('address') to the query
207+
->eagerLoadRelations(), // Adds with('address') to the query
208208
```
209209

210210
### Conditionally Hiding Columns
@@ -213,10 +213,10 @@ Sometimes you may want to hide columns based on certain conditions. You can use
213213

214214
```php
215215
Column::make('Type', 'user.type')
216-
->hideIf(request()->routeIs('this.other.route'))
216+
->hideIf(request()->routeIs('this.other.route')),
217217

218218
Column::make('Last 4', 'card_last_four')
219-
->hideIf(! auth()->user()->isAdmin())
219+
->hideIf(! auth()->user()->isAdmin()),
220220
```
221221

222222
### Excluding from Column Select
@@ -230,11 +230,11 @@ Column::make('Address', 'address.address')
230230

231231
### Preventing clicks if row URL is enabled
232232

233-
If you have row URLs enabled, but you have a specific column you do not want clickable, i.e. in the event there is something else clickable in that row, you may yse the following:
233+
If you have row URLs enabled, but you have a specific column you do not want clickable, i.e. in the event there is something else clickable in that row, you may use the following:
234234

235235
```php
236236
Column::make('Name')
237237
->unclickable(),
238238
```
239239

240-
See more in the [clickable rows documentation](../rows/clickable-rows).
240+
See more in the [clickable rows documentation](../rows/clickable-rows).

docs/columns/column-selection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If you don't want a column to be able to be turned off from the column select bo
1111

1212
```php
1313
Column::make('Address', 'address.address')
14-
->excludeFromColumnSelect()
14+
->excludeFromColumnSelect(),
1515
```
1616

1717
## Available Methods

docs/columns/creating-columns.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ The `columns` method on your component must return an array of Column objects in
88
```php
99
public function columns(): array
1010
{
11-
Column::make('Name'),
12-
Column::make('Email'),
11+
return [
12+
Column::make('Name'),
13+
Column::make('Email'),
14+
];
1315
}
1416
```
1517

@@ -20,13 +22,23 @@ By default, you only need one parameter which acts as the header of the column,
2022
So if you have:
2123

2224
```php
23-
Column::make('Name') // Looks for column `name`
24-
Column::make('Email') // Looks for column `email`
25+
public function columns(): array
26+
{
27+
return [
28+
Column::make('Name'), // Looks for column `name`
29+
Column::make('Email'), // Looks for column `email`
30+
];
31+
}
2532
```
2633

2734
Of course, this won't work in every situation, for example if you have an ID column, Str::snake will convert it to `i_d` which is incorrect. For this situation and any other situation where you want to specify the field name, you can pass it as the second parameter:
2835

2936
```php
30-
Column::make('ID', 'id'),
31-
Column::make('E-mail', 'email'),
37+
public function columns(): array
38+
{
39+
return [
40+
Column::make('ID', 'id'),
41+
Column::make('E-mail', 'email'),
42+
];
43+
}
3244
```

docs/columns/other-column-types.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ If you want the false value to be the green option, you can set:
4848

4949
```php
5050
BooleanColumn::make('Active')
51-
->setSuccessValue(false) // Makes false the 'successful' option
51+
->setSuccessValue(false); // Makes false the 'successful' option
5252
```
5353

5454
That would swap the colors of the icons in the image above.
@@ -67,7 +67,7 @@ You can override this functionality:
6767
BooleanColumn::make('Active')
6868
->setCallback(function(string $value) {
6969
// Figure out what makes $value true
70-
})
70+
}),
7171
```
7272

7373
## Image Columns
@@ -76,24 +76,22 @@ Image columns provide a way to display images in your table without having to us
7676

7777
```php
7878
ImageColumn::make('Avatar')
79-
->location(function($row) {
80-
return storage_path('app/public/avatars/' . $row->id . '.jpg');
81-
})
79+
->location(
80+
fn($row) => storage_path('app/public/avatars/' . $row->id . '.jpg')
81+
),
8282
```
8383

8484
You may also pass an array of attributes to apply to the image tag:
8585

8686
```php
8787
ImageColumn::make('Avatar')
88-
->location(function($row) {
89-
return storage_path('app/public/avatars/' . $row->id . '.jpg');
90-
})
91-
->attributes(function($row) {
92-
return [
93-
'class' => 'rounded-full',
94-
'alt' => $row->name . ' Avatar',
95-
];
96-
})
88+
->location(
89+
fn($row) => storage_path('app/public/avatars/' . $row->id . '.jpg')
90+
)
91+
->attributes(fn($row) => [
92+
'class' => 'rounded-full',
93+
'alt' => $row->name . ' Avatar',
94+
]),
9795
```
9896

9997
## Link Columns
@@ -103,7 +101,7 @@ Link columns provide a way to display HTML links in your table without having to
103101
```php
104102
LinkColumn::make('Action')
105103
->title(fn($row) => 'Edit')
106-
->location(fn($row) => route('admin.users.edit', $row))
104+
->location(fn($row) => route('admin.users.edit', $row)),
107105
```
108106

109107
You may also pass an array of attributes to apply to the `a` tag:
@@ -112,10 +110,8 @@ You may also pass an array of attributes to apply to the `a` tag:
112110
LinkColumn::make('Action')
113111
->title(fn($row) => 'Edit')
114112
->location(fn($row) => route('admin.users.edit', $row))
115-
->attributes(function($row) {
116-
return [
117-
'class' => 'rounded-full',
118-
'alt' => $row->name . ' Avatar',
119-
];
120-
})
113+
->attributes(fn($row) => [
114+
'class' => 'rounded-full',
115+
'alt' => $row->name . ' Avatar',
116+
]),
121117
```

docs/columns/relationships.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,34 @@ To call these relationships, just use the relationship dot-notation string as th
1010
```php
1111
protected $model = User::class;
1212

13-
...
13+
// ...
1414

1515
public function columns(): array {
16-
// Looks for the address column on the address relationship of User.
17-
// $user->address->address
18-
Column::make('Address', 'address.address'),
19-
20-
// Looks for $user->address->group->name
21-
Column::make('Address Group', 'address.group.name'),
22-
23-
// Looks for $user->address->group->city->name
24-
Column::make('Group City', 'address.group.city.name'),
16+
return [
17+
// Looks for the address column on the address relationship of User.
18+
// $user->address->address
19+
Column::make('Address', 'address.address'),
20+
21+
// Looks for $user->address->group->name
22+
Column::make('Address Group', 'address.group.name'),
23+
24+
// Looks for $user->address->group->city->name
25+
Column::make('Group City', 'address.group.city.name'),
26+
];
2527
}
2628
```
2729

2830
The above will join the necessary tables as well as alias the columns for selecting, sorting, searching, etc.:
2931

3032
```sql
31-
select `addresses`.`address` as `address.address`, `address_groups`.`name` as `address.group.name`, `cities`.`name` as `address.group.city.name` from `users` left join `addresses` on `addresses`.`user_id` = `users`.`id` left join `address_groups` on `addresses`.`address_group_id` = `address_groups`.`id` left join `cities` on `address_groups`.`city_id` = `cities`.`id`
33+
SELECT `addresses`.`address` AS `address.address`,
34+
`address_groups`.`name` AS `address.group.name`,
35+
`cities`.`name` AS `address.group.city.name`
36+
FROM `users`
37+
LEFT JOIN `addresses`
38+
ON `addresses`.`user_id` = `users`.`id`
39+
LEFT JOIN `address_groups`
40+
ON `addresses`.`address_group_id` = `address_groups`.`id`
41+
LEFT JOIN `cities`
42+
ON `address_groups`.`city_id` = `cities`.`id`
3243
```

0 commit comments

Comments
 (0)