Skip to content

Commit 31d2c59

Browse files
author
Riccardo Dalla Via
authored
ADD Laravel 10 compatibility (#17)
1 parent d917fac commit 31d2c59

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

.github/workflows/run-tests.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.1, 8.0]
17-
laravel: [9.*]
16+
php: [8.2, 8.1, 8.0]
17+
laravel: [10.*, 9.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20+
- laravel: 10.*
21+
testbench: 8.*
22+
carbon: ^2.63
2023
- laravel: 9.*
2124
testbench: 7.*
25+
carbon: ^2.63
26+
exclude:
27+
- laravel: 10.*
28+
php: 8.0
2229

2330
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2431

@@ -40,7 +47,7 @@ jobs:
4047
4148
- name: Install dependencies
4249
run: |
43-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
50+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
4451
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
4552
4653
- name: Execute tests

composer.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "Laravel Searchable",
44
"keywords": [
55
"maize-tech",
6-
"laravel-searchable"
6+
"laravel",
7+
"searchable"
78
],
89
"homepage": "https://github.com/maize-tech/laravel-searchable",
910
"license": "MIT",
@@ -17,15 +18,14 @@
1718
],
1819
"require": {
1920
"php": "^8.0",
20-
"illuminate/database": "^9.0",
21-
"illuminate/support": "^9.0",
22-
"spatie/laravel-package-tools": "^1.9.2"
21+
"illuminate/database": "^9.0|^10.0",
22+
"illuminate/support": "^9.0|^10.0",
23+
"spatie/laravel-package-tools": "^1.14.1"
2324
},
2425
"require-dev": {
2526
"friendsofphp/php-cs-fixer": "^3.4",
26-
"orchestra/testbench": "^7.0",
27+
"orchestra/testbench": "^7.0|^8.0",
2728
"phpunit/phpunit": "^9.5",
28-
"spatie/laravel-ray": "^1.26",
2929
"vimeo/psalm": "^4.20"
3030
},
3131
"autoload": {

src/Utils/AttributeUtil.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Query\Grammars\PostgresGrammar;
88
use Illuminate\Support\Arr;
99
use Illuminate\Support\Facades\Schema;
10+
use ReflectionMethod;
1011

1112
class AttributeUtil
1213
{
@@ -81,7 +82,17 @@ public static function isJsonAttribute(Model $model, $attribute): bool
8182
public static function formatAttribute(Model $model, $attribute): string
8283
{
8384
if ($attribute instanceof Expression) {
84-
return $attribute->getValue();
85+
$reflectionMethod = new ReflectionMethod(Expression::class, 'getValue');
86+
87+
if ($reflectionMethod->getNumberOfParameters() === 1) {
88+
$grammar = $model::query()->getQuery()->getGrammar();
89+
90+
/** @psalm-suppress TooManyArguments */
91+
return strval($attribute->getValue($grammar));
92+
}
93+
94+
/** @psalm-suppress TooFewArguments */
95+
return strval($attribute->getValue());
8596
}
8697

8798
$attributeName = self::formatAttributeName($model, $attribute);

tests/Utils/AttributeUtilTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function it_should_return_the_expression_if_an_expression_attribute_is_gi
157157

158158
$result = AttributeUtil::formatAttribute($model, $attribute);
159159

160-
$this->assertEquals($attribute, $result);
160+
$this->assertEquals($result, "CONCAT(first_name, ' ', last_name)");
161161
}
162162

163163
/** @test */

0 commit comments

Comments
 (0)