Skip to content

Commit 1eddc64

Browse files
committed
Drop support for Laravel 11 and below
1 parent c057b6d commit 1eddc64

14 files changed

Lines changed: 60 additions & 254 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,11 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
laravel: [13.*, 12.*, 11.*, 10.*, 9.*]
12-
php: ['8.5', '8.4', '8.3', '8.2', '8.1', '8.0']
13-
include:
14-
- laravel: 8.*
15-
php: '8.1'
16-
- laravel: 8.*
17-
php: '8.0'
18-
- laravel: 8.*
19-
php: '7.4'
20-
- laravel: 8.*
21-
php: '7.3'
22-
- laravel: 7.*
23-
php: '8.0'
24-
- laravel: 7.*
25-
php: '7.4'
26-
- laravel: 7.*
27-
php: '7.3'
28-
- laravel: 7.*
29-
php: '7.2'
30-
- laravel: 6.*
31-
php: '8.0'
32-
- laravel: 6.*
33-
php: '7.4'
34-
- laravel: 6.*
35-
php: '7.3'
36-
- laravel: 6.*
37-
php: '7.2'
38-
- laravel: 5.8
39-
php: '7.2'
40-
- laravel: 5.8
41-
php: '7.1'
42-
- laravel: 5.7
43-
php: '7.2'
44-
- laravel: 5.7
45-
php: '7.1'
46-
- laravel: 5.6
47-
php: '7.2'
48-
- laravel: 5.6
49-
php: '7.1'
11+
laravel: [13.*, 12.*]
12+
php: ['8.5', '8.4', '8.3', '8.2']
5013
exclude:
5114
- laravel: 13.*
5215
php: '8.2'
53-
- laravel: 13.*
54-
php: '8.1'
55-
- laravel: 13.*
56-
php: '8.0'
57-
- laravel: 12.*
58-
php: '8.1'
59-
- laravel: 12.*
60-
php: '8.0'
61-
- laravel: 11.*
62-
php: '8.1'
63-
- laravel: 11.*
64-
php: '8.0'
65-
- laravel: 10.*
66-
php: '8.0'
67-
- laravel: 10.*
68-
php: '8.5'
69-
- laravel: 9.*
70-
php: '8.4'
71-
- laravel: 9.*
72-
php: '8.5'
7316

7417
name: L${{ matrix.laravel }} - PHP${{ matrix.php }}
7518

@@ -88,14 +31,8 @@ jobs:
8831
extensions: mbstring, pdo, sqlite, pdo_sqlite, iconv
8932
coverage: none
9033

91-
- name: Fix dependencies
92-
if: ${{ startsWith(matrix.laravel, '11') || startsWith(matrix.laravel, '12') || startsWith(matrix.laravel, '13') }}
93-
run: |
94-
composer require "laravel/serializable-closure:>=1.3" --no-interaction --no-update
9534
- name: Install dependencies
9635
run: |
97-
composer config audit.block-insecure false || true
98-
composer config --no-plugins allow-plugins.kylekatarnls/update-helper true
9936
composer require "illuminate/database:${{ matrix.laravel }}" --no-interaction --no-update
10037
composer update --no-interaction
10138
- name: Execute tests

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
}
1515
],
1616
"require": {
17-
"illuminate/database": ">=5.6 <14.0"
17+
"php": "^8.2",
18+
"illuminate/database": "^12.0|^13.0"
1819
},
1920
"require-dev": {
2021
"ext-sqlite3": "*",
2122
"fakerphp/faker": "^1.18",
22-
"phpunit/phpunit": "^6.0|^8.0|^9.0|^10.0|^11.0|^12.0"
23+
"phpunit/phpunit": "^11.0|^12.0"
2324
},
2425
"autoload": {
2526
"psr-4": {

src/Database/Eloquent/Relations/BelongsTo.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public function associate($model)
5050
$value = $ownerKey[$i];
5151
$this->child->setAttribute($foreignKey, $value);
5252
}
53-
// BC break in 5.8 : https://github.com/illuminate/database/commit/87b9833019f48b88d98a6afc46f38ce37f08237d
54-
$relationName = property_exists($this, 'relationName') ? $this->relationName : $this->relation;
53+
$relationName = $this->relationName;
5554
if ($model instanceof Model) {
5655
$this->child->setRelation($relationName, $model);
5756
// proper unset // https://github.com/illuminate/database/commit/44411c7288fc7b7d4e5680cfcdaa46d348b5c981
@@ -115,9 +114,6 @@ public function addEagerConstraints(array $models)
115114
$keys[] = $this->related->getTable().'.'.$key;
116115
}
117116

118-
// method \Awobaz\Compoships\Database\Eloquent\Relations\HasOneOrMany::whereInMethod
119-
// 5.6 - does not exist
120-
// 5.7 - added in 5.7.17 / https://github.com/illuminate/database/commit/9af300d1c50c9ec526823c1e6548daa3949bf9a9
121117
$this->query->whereIn($keys, $this->getEagerModelKeys($models));
122118
} else {
123119
parent::addEagerConstraints($models);

src/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function addEagerConstraints(array $models)
8585
$modelKeys = $this->getCompositeKeys($models, $this->parentKey);
8686
$qualifiedKeys = $this->qualifyPivotColumn($this->foreignPivotKey);
8787

88-
$query = (method_exists($this, 'getRelationQuery') ? $this->getRelationQuery() : null) ?? $this->query;
88+
$query = $this->getRelationQuery() ?? $this->query;
8989
$query->{$whereIn}($qualifiedKeys, $modelKeys);
9090

9191
if ($modelKeys === []) {
@@ -184,10 +184,8 @@ protected function buildDictionary(Collection $results)
184184

185185
$dictionary = [];
186186

187-
$accessor = property_exists($this, 'accessor') ? $this->accessor : 'pivot';
188-
189187
foreach ($results as $result) {
190-
$key = $this->buildDictionaryKey($result->{$accessor}, $this->foreignPivotKey);
188+
$key = $this->buildDictionaryKey($result->{$this->accessor}, $this->foreignPivotKey);
191189
$dictionary[$key][] = $result;
192190
}
193191

@@ -322,9 +320,7 @@ protected function baseAttachRecord($id, $timed)
322320
$record = $this->addTimestampsToAttachment($record);
323321
}
324322

325-
$pivotValues = property_exists($this, 'pivotValues') ? $this->pivotValues : [];
326-
327-
foreach ($pivotValues as $value) {
323+
foreach ($this->pivotValues as $value) {
328324
$record[$value['column']] = $value['value'];
329325
}
330326

@@ -350,9 +346,7 @@ protected function formatAttachRecords($ids, array $attributes)
350346
$hasTimestamps = $this->hasPivotColumn($this->createdAt())
351347
|| $this->hasPivotColumn($this->updatedAt());
352348

353-
$castedAttributes = method_exists($this, 'castAttributes')
354-
? $this->castAttributes($attributes)
355-
: $attributes;
349+
$castedAttributes = $this->castAttributes($attributes);
356350

357351
foreach ($ids as $value) {
358352
$records[] = array_merge(
@@ -437,22 +431,16 @@ public function newPivotQuery()
437431

438432
$query = $this->newPivotStatement();
439433

440-
if (property_exists($this, 'pivotWheres')) {
441-
foreach ($this->pivotWheres as $arguments) {
442-
$query->where(...$arguments);
443-
}
434+
foreach ($this->pivotWheres as $arguments) {
435+
$query->where(...$arguments);
444436
}
445437

446-
if (property_exists($this, 'pivotWhereIns')) {
447-
foreach ($this->pivotWhereIns as $arguments) {
448-
$query->whereIn(...$arguments);
449-
}
438+
foreach ($this->pivotWhereIns as $arguments) {
439+
$query->whereIn(...$arguments);
450440
}
451441

452-
if (property_exists($this, 'pivotWhereNulls')) {
453-
foreach ($this->pivotWhereNulls as $arguments) {
454-
$query->whereNull(...$arguments);
455-
}
442+
foreach ($this->pivotWhereNulls as $arguments) {
443+
$query->whereNull(...$arguments);
456444
}
457445

458446
foreach ($this->foreignPivotKey as $index => $key) {
@@ -498,10 +486,13 @@ public function detach($ids = null, $touch = true)
498486
return parent::detach($ids, $touch);
499487
}
500488

501-
$using = property_exists($this, 'using') ? $this->using : null;
489+
if ($this->using) {
490+
$results = 0;
491+
$records = $this->getCurrentlyAttachedPivotsForIds($ids);
502492

503-
if ($using && method_exists($this, 'detachUsingCustomClass')) {
504-
$results = $this->detachUsingCustomClass($ids);
493+
foreach ($records as $record) {
494+
$results += $record->delete();
495+
}
505496
} else {
506497
$query = $this->newPivotQuery();
507498

@@ -542,22 +533,15 @@ public function newPivot(array $attributes = [], $exists = false)
542533
return parent::newPivot($attributes, $exists);
543534
}
544535

545-
$pivotValues = property_exists($this, 'pivotValues') ? $this->pivotValues : [];
546-
$attributes = array_merge(array_column($pivotValues, 'value', 'column'), $attributes);
547-
548-
$using = property_exists($this, 'using') ? $this->using : null;
536+
$attributes = array_merge(array_column($this->pivotValues, 'value', 'column'), $attributes);
549537

550-
$pivot = $using
551-
? $using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
538+
$pivot = $this->using
539+
? $this->using::fromRawAttributes($this->parent, $attributes, $this->table, $exists)
552540
: Pivot::fromAttributes($this->parent, $attributes, $this->table, $exists);
553541

554-
$pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey);
555-
556-
if (method_exists($pivot, 'setRelatedModel')) {
557-
$pivot->setRelatedModel($this->related);
558-
}
559-
560-
return $pivot;
542+
return $pivot
543+
->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey)
544+
->setRelatedModel($this->related);
561545
}
562546

563547
/**
@@ -582,18 +566,13 @@ protected function getCurrentlyAttachedPivotsForIds($ids = null)
582566
})
583567
->get()
584568
->map(function ($record) {
585-
$using = property_exists($this, 'using') ? $this->using : null;
586-
$class = $using ?: Pivot::class;
569+
$class = $this->using ?: Pivot::class;
587570

588571
$pivot = $class::fromRawAttributes($this->parent, (array) $record, $this->getTable(), true);
589572

590-
$pivot->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey);
591-
592-
if (method_exists($pivot, 'setRelatedModel')) {
593-
$pivot->setRelatedModel($this->related);
594-
}
595-
596-
return $pivot;
573+
return $pivot
574+
->setPivotKeys($this->foreignPivotKey, $this->relatedPivotKey)
575+
->setRelatedModel($this->related);
597576
});
598577
}
599578

@@ -771,10 +750,15 @@ public function attach($ids, array $attributes = [], $touch = true)
771750
return;
772751
}
773752

774-
$using = property_exists($this, 'using') ? $this->using : null;
753+
if ($this->using) {
754+
$records = $this->formatAttachRecords(
755+
$this->parseIds($ids),
756+
$attributes
757+
);
775758

776-
if ($using && method_exists($this, 'attachUsingCustomClass')) {
777-
$this->attachUsingCustomClass($ids, $attributes);
759+
foreach ($records as $record) {
760+
$this->newPivot($record, false)->save();
761+
}
778762
} else {
779763
$this->newPivotStatement()->insert($this->formatAttachRecords(
780764
$this->parseIds($ids),

src/Database/Eloquent/Relations/HasOneOrMany.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public function addConstraints()
5353
* @param array $models
5454
*
5555
* @return void
56-
*
57-
* >=7.x - no method Illuminate\Database\Eloquent\Relations\Relation::getRelationQuery
58-
* 10.x - no support array keys Illuminate\Database\Eloquent\Relations\Relation::whereInEager
5956
*/
6057
public function addEagerConstraints(array $models)
6158
{
@@ -80,9 +77,6 @@ public function addEagerConstraints(array $models)
8077
* @param string|array $key
8178
*
8279
* @return string
83-
*
84-
* 5.6 - no method \Awobaz\Compoships\Database\Eloquent\Relations\HasOneOrMany::whereInMethod
85-
* added in this commit (5.7.17) https://github.com/illuminate/database/commit/9af300d1c50c9ec526823c1e6548daa3949bf9a9
8680
*/
8781
protected function whereInMethod(Model $model, $key)
8882
{

tests/ComposhipsTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ public function testMake()
154154

155155
public function testHas()
156156
{
157-
if (getLaravelVersion() <= 5.6 && getPHPVersion() >= 7.3) {
158-
$this->markTestIncomplete('This test is broken on laravel 5.6 with PHP 7.3 and earlier!');
159-
}
160157

161158
$allocations = Allocation::has('trackingTasks')
162159
->get()
@@ -170,9 +167,6 @@ public function testHas()
170167
*/
171168
public function testWhereHas()
172169
{
173-
if (getLaravelVersion() <= 5.6 && getPHPVersion() >= 7.3) {
174-
$this->markTestIncomplete('This test is broken on laravel 5.6 with PHP 7.3 and earlier!');
175-
}
176170

177171
$allocations = Allocation::wherehas('trackingTasks')
178172
->get()
@@ -190,9 +184,6 @@ public function testWhereHas()
190184

191185
public function testWhereHasCallback()
192186
{
193-
if (getLaravelVersion() <= 5.6 && getPHPVersion() >= 7.3) {
194-
$this->markTestIncomplete('This test is broken on laravel 5.6 with PHP 7.3 and earlier!');
195-
}
196187

197188
$allocations = Allocation::wherehas('trackingTasks', function ($query) {
198189
$query->where('vehicle_id', 1);
@@ -223,9 +214,6 @@ public function testMixedTypeCompositeKey()
223214

224215
public function testHasForSelfRelation()
225216
{
226-
if (getLaravelVersion() <= 5.6 && getPHPVersion() >= 7.3) {
227-
$this->markTestIncomplete('This test is broken on laravel 5.6 with PHP 7.3 and earlier!');
228-
}
229217

230218
$trackingTask = TrackingTask::has('subTasks')
231219
->get()
@@ -236,9 +224,6 @@ public function testHasForSelfRelation()
236224

237225
public function testHasWithBelongsToRelation()
238226
{
239-
if (getLaravelVersion() <= 5.6 && getPHPVersion() >= 7.3) {
240-
$this->markTestIncomplete('This test is broken on laravel 5.6 with PHP 7.3 and earlier!');
241-
}
242227

243228
$pickup_times = PickupTime::has('pickupPoint')
244229
->get()
@@ -263,9 +248,6 @@ public function testAssociateOnbelongsTo()
263248

264249
public function testHasOneOrManyFactoryRelationship()
265250
{
266-
if (getLaravelVersion() < 8.0) {
267-
$this->markTestIncomplete('This test is broken on laravel 7.x and earlier!');
268-
}
269251

270252
$allocation = Allocation::factory()
271253
->has(TrackingTask::factory()->count(2)) // A Compoships relationship

tests/Factories/DumbHasFactory.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)