mirror of https://github.com/kcal-app/kcal.git
Upgrade to Laravel 9
This commit is contained in:
parent
9b0ffde30c
commit
5c29150ae1
2101
.phpstorm.meta.php
2101
.phpstorm.meta.php
File diff suppressed because it is too large
Load Diff
1588
_ide_helper.php
1588
_ide_helper.php
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,7 @@ use App\Models\Recipe;
|
||||||
use App\Search\Ingredient;
|
use App\Search\Ingredient;
|
||||||
use ElasticScoutDriverPlus\Builders\MultiMatchQueryBuilder;
|
use ElasticScoutDriverPlus\Builders\MultiMatchQueryBuilder;
|
||||||
use ElasticScoutDriverPlus\Builders\TermsQueryBuilder;
|
use ElasticScoutDriverPlus\Builders\TermsQueryBuilder;
|
||||||
|
use ElasticScoutDriverPlus\Support\Query;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
@ -42,11 +43,10 @@ class IngredientPickerController extends Controller
|
||||||
* Search using an ElasticSearch service.
|
* Search using an ElasticSearch service.
|
||||||
*/
|
*/
|
||||||
private function searchWithElasticSearch(string $term): Collection {
|
private function searchWithElasticSearch(string $term): Collection {
|
||||||
return Food::boolSearch()
|
$query = Query::bool()
|
||||||
->join(Recipe::class)
|
|
||||||
|
|
||||||
// Attempt to match exact phrase first.
|
// Attempt to match exact phrase first.
|
||||||
->should('match_phrase', ['name' => $term])
|
->should(Query::matchPhrase()->field('name')->query($term))
|
||||||
|
|
||||||
// Attempt multi-match search on all relevant fields with search-as-you-type on name.
|
// Attempt multi-match search on all relevant fields with search-as-you-type on name.
|
||||||
->should((new MultiMatchQueryBuilder())
|
->should((new MultiMatchQueryBuilder())
|
||||||
|
@ -57,10 +57,12 @@ class IngredientPickerController extends Controller
|
||||||
->fuzziness('AUTO'))
|
->fuzziness('AUTO'))
|
||||||
|
|
||||||
// Attempt to match on any tags in the term.
|
// Attempt to match on any tags in the term.
|
||||||
->should((new TermsQueryBuilder())
|
->should((new TermsQueryBuilder())->field('tags')->values(explode(' ', $term)))
|
||||||
->terms('tags', explode(' ', $term)))
|
|
||||||
|
|
||||||
// Get resulting models.
|
->minimumShouldMatch(1);
|
||||||
|
|
||||||
|
return Food::searchQuery($query)
|
||||||
|
->join(Recipe::class)
|
||||||
->execute()
|
->execute()
|
||||||
->models();
|
->models();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||||
|
|
||||||
class TrustProxies extends Middleware
|
class TrustProxies extends Middleware
|
||||||
{
|
{
|
||||||
|
@ -15,5 +15,10 @@ class TrustProxies extends Middleware
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
protected $headers =
|
||||||
|
Request::HEADER_X_FORWARDED_FOR |
|
||||||
|
Request::HEADER_X_FORWARDED_HOST |
|
||||||
|
Request::HEADER_X_FORWARDED_PORT |
|
||||||
|
Request::HEADER_X_FORWARDED_PROTO |
|
||||||
|
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,9 @@ use App\Models\Traits\Journalable;
|
||||||
use App\Models\Traits\Sluggable;
|
use App\Models\Traits\Sluggable;
|
||||||
use App\Models\Traits\Taggable;
|
use App\Models\Traits\Taggable;
|
||||||
use App\Support\Number;
|
use App\Support\Number;
|
||||||
use ElasticScoutDriverPlus\QueryDsl;
|
use ElasticScoutDriverPlus\Searchable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Laravel\Scout\Searchable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App\Models\Food
|
* App\Models\Food
|
||||||
|
@ -80,7 +79,6 @@ final class Food extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use Ingredient;
|
use Ingredient;
|
||||||
use Journalable;
|
use Journalable;
|
||||||
use QueryDsl;
|
|
||||||
use Searchable;
|
use Searchable;
|
||||||
use Sluggable;
|
use Sluggable;
|
||||||
use Taggable;
|
use Taggable;
|
||||||
|
|
|
@ -9,12 +9,11 @@ use App\Models\Traits\Sluggable;
|
||||||
use App\Models\Traits\Taggable;
|
use App\Models\Traits\Taggable;
|
||||||
use App\Support\Number;
|
use App\Support\Number;
|
||||||
use App\Support\Nutrients;
|
use App\Support\Nutrients;
|
||||||
use ElasticScoutDriverPlus\QueryDsl;
|
use ElasticScoutDriverPlus\Searchable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Scout\Searchable;
|
|
||||||
use Spatie\Image\Manipulations;
|
use Spatie\Image\Manipulations;
|
||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||||
|
@ -91,7 +90,6 @@ final class Recipe extends Model implements HasMedia
|
||||||
use Ingredient;
|
use Ingredient;
|
||||||
use InteractsWithMedia;
|
use InteractsWithMedia;
|
||||||
use Journalable;
|
use Journalable;
|
||||||
use QueryDsl;
|
|
||||||
use Searchable;
|
use Searchable;
|
||||||
use Sluggable;
|
use Sluggable;
|
||||||
use Taggable;
|
use Taggable;
|
||||||
|
|
|
@ -9,39 +9,38 @@
|
||||||
"ext-gd": "*",
|
"ext-gd": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"algolia/algoliasearch-client-php": "^2.7",
|
"algolia/algoliasearch-client-php": "^3.2",
|
||||||
"algolia/scout-extended": "^1.15",
|
"algolia/scout-extended": "^2.0",
|
||||||
"babenkoivan/elastic-migrations": "^1.4",
|
"babenkoivan/elastic-migrations": "^2.0",
|
||||||
"babenkoivan/elastic-scout-driver": "^1.3",
|
"babenkoivan/elastic-scout-driver": "^2.0",
|
||||||
"babenkoivan/elastic-scout-driver-plus": "^2.0",
|
"babenkoivan/elastic-scout-driver-plus": "^3.3",
|
||||||
"cloudcreativity/laravel-json-api": "^3.2",
|
"cloudcreativity/laravel-json-api": "^4.0",
|
||||||
"cviebrock/eloquent-sluggable": "^8.0",
|
"cviebrock/eloquent-sluggable": "^9.0",
|
||||||
"doctrine/dbal": "^3.0",
|
"doctrine/dbal": "^3.0",
|
||||||
"fideloper/proxy": "^4.4",
|
|
||||||
"fruitcake/laravel-cors": "^2.0",
|
"fruitcake/laravel-cors": "^2.0",
|
||||||
"guzzlehttp/guzzle": "^7.0.1",
|
"guzzlehttp/guzzle": "^7.0.1",
|
||||||
"laravel/framework": "^8.12",
|
"laravel/framework": "^9.0",
|
||||||
"laravel/scout": "^8.6",
|
"laravel/scout": "^9.0",
|
||||||
"laravel/tinker": "^2.5",
|
"laravel/tinker": "^2.7",
|
||||||
"league/flysystem-aws-s3-v3": "~1.0",
|
"league/flysystem-aws-s3-v3": "^3.0",
|
||||||
"phospr/fraction": "^1.2",
|
"phospr/fraction": "^1.2",
|
||||||
"spatie/laravel-csp": "^2.6",
|
"spatie/laravel-csp": "^2.6",
|
||||||
"spatie/laravel-medialibrary": "^9.0.0",
|
"spatie/laravel-medialibrary": "^10.0",
|
||||||
"spatie/laravel-tags": "^3.0"
|
"spatie/laravel-tags": "^4.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-ide-helper": "^2.9",
|
"barryvdh/laravel-ide-helper": "^2.9",
|
||||||
"brianium/paratest": "^6.2",
|
"brianium/paratest": "^6.2",
|
||||||
"cloudcreativity/json-api-testing": "^3.2",
|
"cloudcreativity/json-api-testing": "^4.0",
|
||||||
"facade/ignition": "^2.5",
|
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
"laravel/breeze": "^1.0",
|
"laravel/breeze": "^1.0",
|
||||||
"laravel/sail": "^1.10",
|
"laravel/sail": "^1.10",
|
||||||
"mockery/mockery": "^1.4.2",
|
"mockery/mockery": "^1.4.2",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^6.1",
|
||||||
"nunomaduro/larastan": "^0.6.13",
|
"nunomaduro/larastan": "^2.0",
|
||||||
"php-coveralls/php-coveralls": "^2.4",
|
"php-coveralls/php-coveralls": "^2.4",
|
||||||
"phpunit/phpunit": "^9.3.3"
|
"phpunit/phpunit": "^9.3.3",
|
||||||
|
"spatie/laravel-ignition": "^1.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Http\Controllers;
|
namespace Tests\Feature\Http\Controllers;
|
||||||
|
|
||||||
|
use Algolia\AlgoliaSearch\Exceptions\UnreachableException;
|
||||||
use App\Http\Controllers\IngredientPickerController;
|
use App\Http\Controllers\IngredientPickerController;
|
||||||
use App\Models\Food;
|
use App\Models\Food;
|
||||||
use App\Models\Recipe;
|
use App\Models\Recipe;
|
||||||
|
@ -42,8 +43,8 @@ class IngredientPickerControllerTest extends LoggedInTestCase
|
||||||
*/
|
*/
|
||||||
public function testCanSearchWithAlgolia(): void
|
public function testCanSearchWithAlgolia(): void
|
||||||
{
|
{
|
||||||
$this->expectException(ConnectException::class);
|
$this->expectException(UnreachableException::class);
|
||||||
$this->expectExceptionMessageMatches("/Could not resolve host: \-dsn\.algolia\.net/");
|
$this->expectExceptionMessage("Impossible to connect, please check your Algolia Application Id.");
|
||||||
|
|
||||||
Config::set('scout.driver', 'algolia');
|
Config::set('scout.driver', 'algolia');
|
||||||
$response = $this->get($this->buildUrl(['term' => 'butter']));
|
$response = $this->get($this->buildUrl(['term' => 'butter']));
|
||||||
|
|
Loading…
Reference in New Issue