1. Go to this page and download the library: Download mattsplat/dynamic-loading library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$users = User::all()->dynamicLoad(
'latest_login',
fn ($m) => Login::where('user_id', $m->id)->latest()->limit(1),
null, // $relation_key — let it default to user_id
null, // $model_key — let it default to the primary key
true // $single
);
$users->first()->latest_login; // a single Login model, or null
$users->first()->latest_login?->created_at;
$users = User::all()->dynamicLoadWhereIn(
'recent_posts',
fn ($keys) => Post::whereNotNull('published_at')
->where('published_at', '>=', now()->subMonth())
->latest('published_at'),
'author_id' // column on posts + the key results are grouped by
);
$users->first()->recent_posts; // Eloquent\Collection of Post models
$users = User::all()->dynamicLoadWhereIn(
'latest_post',
fn ($keys) => Post::latest('published_at'),
'author_id',
null,
true // $single → one Post or null per user
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.