diff --git a/app/Http/Controllers/ActieWijzerController.php b/app/Http/Controllers/ActieWijzerController.php index ee80581f..55ec6d93 100644 --- a/app/Http/Controllers/ActieWijzerController.php +++ b/app/Http/Controllers/ActieWijzerController.php @@ -11,6 +11,7 @@ use App\Models\Theme; use Artesaos\SEOTools\Facades\SEOTools; use Artesaos\SEOTools\Facades\SEOMeta; +use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; @@ -124,7 +125,9 @@ public function result(Request $request) { }); // Get referentie_types and calculate the similarity with the score_vector - $referentie_types = ReferentieType::published()->get(); + $referentie_types = ReferentieType::published()->with(['referenties' => function (Builder $query) { + $query->inRandomOrder()->limit(3); + }])->get(); foreach ($referentie_types as $rt) { $dims_filtered = array_filter($dimensions->toArray(), function($d) use ($rt) { return in_array($d['id'], array_keys($rt->score_vector)); diff --git a/app/Models/Referentie.php b/app/Models/Referentie.php index 17b11293..7fef53af 100644 --- a/app/Models/Referentie.php +++ b/app/Models/Referentie.php @@ -7,6 +7,7 @@ class Referentie extends Model { + use \Staudenmeir\EloquentEagerLimit\HasEagerLimit; protected $table = 'referenties'; diff --git a/app/Models/ReferentieType.php b/app/Models/ReferentieType.php index 4fcb2837..e17c320d 100644 --- a/app/Models/ReferentieType.php +++ b/app/Models/ReferentieType.php @@ -8,7 +8,8 @@ class ReferentieType extends Model { - + use \Staudenmeir\EloquentEagerLimit\HasEagerLimit; + protected $table = 'referentie_types'; protected $fillable = [ diff --git a/composer.json b/composer.json index a2ae87c0..844aacb7 100755 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "matanyadaev/laravel-eloquent-spatial": "^4.2", "mcordingley/linearalgebra": "^3.0", "orangehill/iseed": "^3.0", + "staudenmeir/eloquent-eager-limit": "^1.8", "tcg/voyager": "^1.7", "tymon/jwt-auth": "^2.1" }, diff --git a/composer.lock b/composer.lock index 4902240a..44133e70 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a6e3d7009378dd0d745298834d9c0db7", + "content-hash": "afc67fb454c454afc507e6c9ee3999a5", "packages": [ { "name": "arrilot/laravel-widgets", @@ -4649,6 +4649,56 @@ ], "time": "2023-11-08T05:53:05+00:00" }, + { + "name": "staudenmeir/eloquent-eager-limit", + "version": "v1.8.3", + "source": { + "type": "git", + "url": "https://github.com/staudenmeir/eloquent-eager-limit.git", + "reference": "4d242d948955d155bc7fae8b1738818b16f7d333" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/staudenmeir/eloquent-eager-limit/zipball/4d242d948955d155bc7fae8b1738818b16f7d333", + "reference": "4d242d948955d155bc7fae8b1738818b16f7d333", + "shasum": "" + }, + "require": { + "illuminate/database": "^10.0", + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Staudenmeir\\EloquentEagerLimit\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonas Staudenmeir", + "email": "mail@jonas-staudenmeir.de" + } + ], + "description": "Laravel Eloquent eager loading with limit", + "support": { + "issues": "https://github.com/staudenmeir/eloquent-eager-limit/issues", + "source": "https://github.com/staudenmeir/eloquent-eager-limit/tree/v1.8.3" + }, + "funding": [ + { + "url": "https://paypal.me/JonasStaudenmeir", + "type": "custom" + } + ], + "time": "2023-07-12T21:15:26+00:00" + }, { "name": "symfony/console", "version": "v6.4.6", diff --git a/resources/views/actiewijzer/result.blade.php b/resources/views/actiewijzer/result.blade.php index 38068d08..4caf6621 100755 --- a/resources/views/actiewijzer/result.blade.php +++ b/resources/views/actiewijzer/result.blade.php @@ -9,7 +9,7 @@ -