From a3bed7873586c41e48af6400fd275e23d1c1077b Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Fri, 4 Feb 2022 10:41:29 +0100 Subject: [PATCH] Support for Laravel 9 (#53) --- .github/workflows/run-tests.yml | 65 +++++++++++++++++---------------- CHANGELOG.md | 4 ++ README.md | 2 +- composer.json | 4 +- src/Searcher.php | 4 +- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8c8d806..47f3119 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,11 +9,13 @@ jobs: fail-fast: true matrix: php: [8.1, 8.0] - laravel: [8.*] + laravel: [9.*, 8.*] dependency-version: [prefer-lowest, prefer-stable] include: - - laravel: 8.* - testbench: 6.* + - laravel: 9.* + testbench: 7.* + - laravel: 8.* + testbench: 6.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -30,33 +32,32 @@ jobs: - 3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ~/.composer/cache/files - key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, mysql, mysqli, pdo_mysql - coverage: none - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/phpunit - env: - DB_DATABASE: protone_media_db_test - DB_USERNAME: protone_media_db_test - DB_PASSWORD: secret - DB_PORT: ${{ job.services.mysql.ports[3306] }} \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, mysql, mysqli, pdo_mysql + coverage: none + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit + env: + DB_DATABASE: protone_media_db_test + DB_USERNAME: protone_media_db_test + DB_PASSWORD: secret + DB_PORT: ${{ job.services.mysql.ports[3306] }} diff --git a/CHANGELOG.md b/CHANGELOG.md index ae9850c..9108c30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-cross-eloquent-search` will be documented in this file +## 2.7.0 - 2022-02-04 + +- Support for Laravel 9 + ## 2.6.1 - 2021-12-22 - Bugfix for excluding models when searching for relations without a search term (fixes #37). diff --git a/README.md b/README.md index 4c6dc5f..4618a67 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Hey! We've built a Docker-based deployment tool to launch apps and sites fully c * PHP 8.0 + 8.1 * MySQL 5.7+ -* Laravel 8.0 +* Laravel 8.0 or 9.0 ## Features diff --git a/composer.json b/composer.json index 2efc477..4ed6304 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ ], "require": { "php": "^8.0|^8.1", - "illuminate/support": "^8.79" + "illuminate/support": "^8.79|^9.0" }, "require-dev": { "mockery/mockery": "^1.3.3", - "orchestra/testbench": "^6.23", + "orchestra/testbench": "^6.23|^7.0", "phpunit/phpunit": "^9.4" }, "autoload": { diff --git a/src/Searcher.php b/src/Searcher.php index 9dc36cb..a31f844 100644 --- a/src/Searcher.php +++ b/src/Searcher.php @@ -370,10 +370,12 @@ public function simplePaginate($perPage = 15, $pageName = 'page', $page = null): */ public function parseTerms(string $terms, callable $callback = null): Collection { + $callback = $callback ?: fn () => null; + return Collection::make(str_getcsv($terms, ' ', '"')) ->filter() ->values() - ->when($callback, function ($terms, $callback) { + ->when($callback !== null, function ($terms) use ($callback) { return $terms->each(fn ($value, $key) => $callback($value, $key)); }); }