Skip to content

Commit 248a583

Browse files
committed
Code cleanup, utilizes whereColumn
1 parent 9d57f33 commit 248a583

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/ServiceProvider.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,50 @@ public function boot()
1818
return $this->where('id', function ($sub) use ($where) {
1919
$sub->from($this->from)
2020
->selectRaw('max(id)')
21-
->whereRaw($where['first'] . ' = ' . $where['second']);
21+
->whereColumn($where['first'], $where['second']);
2222
});
2323
});
2424

2525
Builder::macro('whereLatest', function ($column, $value) {
2626
return $this->latestRelation()->where($column, $value);
2727
});
28+
29+
// Builder::macro('latestRelation', function ()
30+
// {
31+
// if(! $where = $this->wheres[0]['second'] ?? null) {
32+
// throw new \InvalidArgumentException('Second join parameter is not specified. The latestRelation() method should only be called from within a whereHas() on a hasMany relationship.');
33+
// }
34+
35+
// list($table, $parentRelatedColumn) = explode('.', $where);
36+
37+
// return $this->where($table . '.id', function ($sub) use ($where, $table, $parentRelatedColumn) {
38+
// $sub->select('id')
39+
// ->from($table . ' AS sub')
40+
// ->whereColumn('sub.' . $parentRelatedColumn, $where)
41+
// ->latest()
42+
// ->take(1);
43+
// });
44+
// });
45+
46+
// Builder::macro('whereLatest', function ($column, $value)
47+
// {
48+
// return $this->latestRelation()->where($column, $value);
49+
// });
50+
51+
// Builder::macro('latestRelationTwo', function () {
52+
// if(! $where = $this->wheres[0] ?? null) {
53+
// throw new \InvalidArgumentException('Second join parameter is not specified. The latestRelation() method should only be called from within a whereHas() on a hasMany relationship.');
54+
// }
55+
56+
// return $this->where('id', function ($sub) use ($where) {
57+
// $sub->from($this->from)
58+
// ->selectRaw('max(id)')
59+
// ->whereRaw($where['first'] . ' = ' . $where['second']);
60+
// });
61+
// });
62+
63+
// Builder::macro('whereLatestTwo', function ($column, $value) {
64+
// return $this->latestRelationTwo()->where($column, $value);
65+
// });
2866
}
2967
}

0 commit comments

Comments
 (0)