Skip to content

Commit aba2b63

Browse files
authored
Merge pull request #1856 from rappasoft/development
Docs Update - One of Many Column Example
2 parents 1e20fb0 + e14287d commit aba2b63

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

docs/filters/available-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,4 @@ Allows you to pass a string to use a wire:model.live.debounce.Xms approach
455455
'maxlength' => '25',
456456
])
457457
->setWireDebounce(50)
458-
```
458+
```

docs/misc/one-of-many-example.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: One Of Many Example
3+
weight: 8
4+
---
5+
6+
When trying to retrieve "OneOfMany", you may experience duplicate records.
7+
8+
Core functionality for this will be added in due course, this is simply a work-around.
9+
10+
In the meantime, to avoid this, you can use the following approach.
11+
12+
This example assumes two Models:
13+
User -> HasMany -> Things
14+
15+
### Models
16+
#### User
17+
id
18+
name
19+
created_at
20+
updated_at
21+
etc
22+
23+
```php
24+
public function things(): \Illuminate\Database\Eloquent\Relations\HasMany
25+
{
26+
return $this->hasMany(Things::class);
27+
}
28+
```
29+
30+
#### Things
31+
id
32+
name
33+
user_id
34+
created_at
35+
updated_at
36+
37+
### Table
38+
The following is the table code for this example, and retrieves the most recently created "Thing"
39+
40+
#### Column
41+
```php
42+
Column::make('Latest Thing')
43+
->label(
44+
fn ($row, Column $column) => $row->things->first()->name
45+
),
46+
```
47+
48+
#### Builder
49+
```php
50+
public function builder(): Builder {
51+
52+
return User::query()->with(['things' => function ($query) {
53+
$query->select(['id','user_id','name'])->orderBy('created_at', 'desc')->limit(1);
54+
}]);
55+
56+
}
57+
```
58+
59+
Core functionality for this will be added in due course, this is simply a work-around.

tests/Views/Filters/DateTimeFilterTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,6 @@ public function test_can_set_text_filter_wireable_live(): void
164164

165165
$this->assertSame('live.debounce.500ms', self::$filterInstance->getWireableMethod());
166166
$this->assertSame('wire:model.live.debounce.500ms=filterComponents.active', self::$filterInstance->getWireMethod('filterComponents.'.self::$filterInstance->getKey()));
167-
}
168167

169-
public function test_check_if_has_locale(): void
170-
{
171-
$this->assertFalse(self::$filterInstance->hasPillsLocale());
172-
self::$filterInstance->setPillsLocale('fr');
173-
$this->assertTrue(self::$filterInstance->hasPillsLocale());
174-
}
175-
176-
public function test_check_if_can_get_locale(): void
177-
{
178-
$this->assertFalse(self::$filterInstance->hasPillsLocale());
179-
$this->assertSame('en', self::$filterInstance->getPillsLocale());
180-
self::$filterInstance->setPillsLocale('fr');
181-
$this->assertTrue(self::$filterInstance->hasPillsLocale());
182-
$this->assertSame('fr', self::$filterInstance->getPillsLocale());
183-
self::$filterInstance->setPillsLocale('de');
184-
$this->assertSame('de', self::$filterInstance->getPillsLocale());
185-
$this->assertTrue(self::$filterInstance->hasPillsLocale());
186168
}
187169
}

0 commit comments

Comments
 (0)