PHP code example of staudenmeir / eloquent-eager-limit
1. Go to this page and download the library: Download staudenmeir/eloquent-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/ */
staudenmeir / eloquent-eager-limit example snippets
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function posts()
{
return $this->hasMany('App\Post');
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with(['posts' => function ($query) {
$query->latest()->limit(10);
}])->get();
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function latestPost()
{
return $this->hasOne('App\Post')->latest()->limit(1);
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with('latestPost')->get();
class User extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function posts()
{
return $this->hasMany('App\Post');
}
}
class Post extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
$users = User::with(['posts' => function ($query) {
$query->latest()->offset(5)->limit(10);
}])->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.