1. Go to this page and download the library: Download mpyw/compoships-eager-limit 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/ */
mpyw / compoships-eager-limit example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use Mpyw\ComposhipsEagerLimit\ComposhipsEagerLimit;
class Post extends Model
{
use ComposhipsEagerLimit;
public function comments()
{
return $this->hasMany(Comment::class);
}
public function authorComments()
{
return $this->hasMany(Comment::class, ['post_id', 'user_id'], ['id', 'user_id']);
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
use Mpyw\ComposhipsEagerLimit\ComposhipsEagerLimit;
class Comment extends Model
{
use ComposhipsEagerLimit;
}
$posts = Post::with(['authorComments' => function ($query) {
$query->limit(3)->offset(1);
}])->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.