Repository: ajcastro/eager-load-pivot-relations
Branch: master
Commit: 9bfeb4a5d659
Files: 31
Total size: 34.3 KB
Directory structure:
gitextract__wxmb_sj/
├── .gitattributes
├── .github/
│ └── workflows/
│ └── tests.yml
├── .gitignore
├── README.md
├── composer.json
├── phpunit.xml.dist
├── src/
│ ├── EagerLoadPivotBuilder.php
│ └── EagerLoadPivotTrait.php
└── tests/
├── Database/
│ ├── Factories/
│ │ ├── BrandFactory.php
│ │ ├── CarFactory.php
│ │ ├── CarUserFactory.php
│ │ ├── ColorFactory.php
│ │ ├── TireFactory.php
│ │ └── UserFactory.php
│ └── Migrations/
│ ├── 2014_10_12_000000_create_users_table.php
│ ├── 2014_10_12_100000_create_password_resets_table.php
│ ├── 2019_06_02_131048_create_brands_table.php
│ ├── 2019_06_02_131049_create_cars_table.php
│ ├── 2019_06_02_131100_create_colors_table.php
│ ├── 2019_06_02_131120_create_car_user_table.php
│ └── 2019_06_02_131148_create_tires_table.php
├── Models/
│ ├── Brand.php
│ ├── Car.php
│ ├── CarUser.php
│ ├── Color.php
│ ├── Tire.php
│ └── User.php
├── TestCase.php
└── Unit/
├── CountTest.php
├── PaginateTest.php
└── PivotTest.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
================================================
FILE: .github/workflows/tests.yml
================================================
name: Tests
on:
pull_request:
push:
branches: [master, main]
jobs:
test:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php: [7.2, 7.3, 7.4, 8.0, 8.1]
stability: [prefer-lowest, prefer-stable]
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} Test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pdo
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none
- name: Install dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
- name: Run tests
run: ./vendor/bin/phpunit
vendor/bin/phpunit --verbose
================================================
FILE: .gitignore
================================================
/vendor
composer.lock
*.cache
================================================
FILE: README.md
================================================
# Laravel Eloquent: Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Medium Story: https://medium.com/@ajcastro29/laravel-eloquent-eager-load-pivot-relations-dba579f3fd3a
## Installation
```
composer require ajcastro/eager-load-pivot-relations
```
## Usage and Example
There are use-cases where in a pivot model has relations to be eager loaded.
Example, in a procurement system, we have the following:
**Tables**
```
items
- id
- name
units
- id
- name (pc, box, etc...)
plans (annual procurement plan)
- id
plan_item (pivot for plans and items)
- id
- plan_id
- item_id
- unit_id
```
**Models**
```php
class Unit extends \Eloquent {
}
use AjCastro\EagerLoadPivotRelations\EagerLoadPivotTrait;
class Item extends \Eloquent
{
// Use the trait here to override eloquent builder.
// It is used in this model because it is the relation model defined in
// Plan::items() relation.
use EagerLoadPivotTrait;
public function plans()
{
return $this->belongsToMany('Plan', 'plan_item');
}
}
class Plan extends \Eloquent
{
public function items()
{
return $this->belongsToMany('Item', 'plan_item')
->using('PlanItem')
// make sure to include the necessary foreign key in this case the `unit_id`
->withPivot('unit_id', 'qty', 'price');
}
}
// Pivot model
class PlanItem extends \Illuminate\Database\Eloquent\Relations\Pivot
{
protected $table = 'plan_item';
public function unit()
{
return $this->belongsTo('Unit');
}
}
```
From the code above, `plans` and `items` has `Many-to-Many` relationship. Each item in a plan has a selected `unit`, unit of measurement.
It also possible for other scenario that the pivot model will have other many relations.
## Eager Loading Pivot Relations
Use keyword `pivot` in eager loading pivot models. So from the example above, the pivot model `PlanItem` can eager load the `unit` relation by doing this:
```
return Plan::with('items.pivot.unit')->get();
```
The resulting data structure will be:

You may also access other relations for example:
```
return Plan::with([
'items.pivot.unit',
'items.pivot.unit.someRelation',
'items.pivot.anotherRelation',
// It is also possible to eager load nested pivot models
'items.pivot.unit.someBelongsToManyRelation.pivot.anotherRelationFromAnotherPivot',
])->get();
```
## Custom Pivot Accessor
You can customize the __"pivot accessor"__, so instead of using the keyword `pivot`, we can declare it as `planItem`.
Just chain the `as()` method in the definition of the `BelongsToMany` relation.
```php
class Plan extends \Eloquent
{
public function items()
{
return $this->belongsToMany('Item', 'plan_item')
->withPivot('unit_id', 'qty', 'price')
->using('PlanItem')
->as('planItem');
}
}
```
Make sure we also use the trait
to our main model which is the `Plan` model, because the package needs to acess
the belongsToMany relation (`items` relation) to recognize the used pivot acessor.
```php
use AjCastro\EagerLoadPivotRelations\EagerLoadPivotTrait;
class Plan extends \Eloquent
{
use EagerLoadPivotTrait;
}
```
So instead of using `pivot`, we can eager load it by defined pivot accessor `planItem`.
```php
return Plan::with('items.planItem.unit')->get();
```
```php
$plan = Plan::with('items.planItem.unit');
foreach ($plan->items as $item) {
$unit = $item->planItem->unit;
echo $unit->name;
}
```
## Other Examples and Use-cases
https://github.com/ajcastro/eager-load-pivot-relations-examples
================================================
FILE: composer.json
================================================
{
"name": "ajcastro/eager-load-pivot-relations",
"description": "Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Arjon Jason Castro",
"email": "ajcastro29@gmail.com"
}
],
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"laravel/framework": ">= 5.0.0",
"laravel/legacy-factories": ">= 1.0.0",
"orchestra/testbench": ">= 3.0.0",
"phpunit/phpunit": ">= 6.0.0"
},
"autoload": {
"psr-4": {
"AjCastro\\EagerLoadPivotRelations\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"AjCastro\\EagerLoadPivotRelations\\Tests\\": "tests"
},
"classmap": [
"tests/Database/Migrations"
]
},
"extra": {
"laravel": {
"providers": [
],
"aliases": {
}
}
}
}
================================================
FILE: phpunit.xml.dist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="date.timezone" value="UTC" />
<ini name="intl.default_locale" value="C.UTF-8" />
<ini name="memory_limit" value="2048M" />
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
</php>
</phpunit>
================================================
FILE: src/EagerLoadPivotBuilder.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations;
use Closure;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class EagerLoadPivotBuilder extends Builder
{
protected static $knownPivotAccessors = [
'pivot',
];
/**
* Override.
* Eagerly load the relationship on a set of models.
*
* @param array $models
* @param string $name
* @param \Closure $constraints
* @return array
*/
protected function eagerLoadRelation(array $models, $name, Closure $constraints)
{
$this->watchForPivotAccessors($name);
if ($this->isPivotAccessor($name)) {
$this->eagerLoadPivotRelations($models, $name);
return $models;
}
return parent::eagerLoadRelation($models, $name, $constraints);
}
/**
* Watch for pivot accessors to register it as known pivot accessors.
*
* @param string $name
* @return void
*/
protected function watchForPivotAccessors($name)
{
$model = $this->getModel();
if (!method_exists($model->newInstance(), $name)) {
return;
}
$relation = $model->newInstance()->$name();
if ($relation instanceof BelongsToMany) {
static::$knownPivotAccessors[] = $relation->getPivotAccessor();
}
}
/**
* If relation name is a pivot accessor.
*
* @param string $name
* @return boolean
*/
protected function isPivotAccessor($name)
{
return in_array($name, static::$knownPivotAccessors);
}
/**
* Eager load pivot relations.
*
* @param array $models
* @param string $pivotAccessor
* @return void
*/
protected function eagerLoadPivotRelations($models, $pivotAccessor)
{
$pivots = Arr::pluck($models, $pivotAccessor);
$pivots = head($pivots)->newCollection($pivots);
$pivots->load($this->getPivotEagerLoadRelations($pivotAccessor));
}
/**
* Get the pivot relations to be eager loaded.
*
* @param string $pivotAccessor
* @return array
*/
protected function getPivotEagerLoadRelations($pivotAccessor)
{
$relations = array_filter($this->eagerLoad, function ($relation) use ($pivotAccessor) {
return $relation !== $pivotAccessor && Str::contains($relation, $pivotAccessor);
}, ARRAY_FILTER_USE_KEY);
return array_combine(
array_map(function ($relation) use ($pivotAccessor) {
return substr($relation, strlen("{$pivotAccessor}."));
}, array_keys($relations)),
array_values($relations)
);
}
}
================================================
FILE: src/EagerLoadPivotTrait.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations;
trait EagerLoadPivotTrait
{
/**
* Create a new Eloquent query builder for the model.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function newEloquentBuilder($query)
{
return new EagerLoadPivotBuilder($query);
}
}
================================================
FILE: tests/Database/Factories/BrandFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Brand;
use Illuminate\Database\Eloquent\Factories\Factory;
class BrandFactory extends Factory
{
protected $model = Brand::class;
public function definition()
{
return [
'name' => $this->faker->word,
'logo' => $this->faker->imageUrl,
];
}
}
================================================
FILE: tests/Database/Factories/CarFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Brand;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Car;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AjCastro\EagerLoadPivotRelations\Tests\Models\Car>
*/
class CarFactory extends Factory
{
protected $model = Car::class;
public function definition()
{
return [
'model' => $this->faker->words(rand(2, 4), true),
'brand_id' => function()
{
return Brand::factory()->create()->id;
}
];
}
}
================================================
FILE: tests/Database/Factories/CarUserFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Car;
use AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Color;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Tire;
use AjCastro\EagerLoadPivotRelations\Tests\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser>
*/
class CarUserFactory extends Factory
{
protected $model = CarUser::class;
public function definition()
{
return [
'car_id' => function() {
return Car::factory()->create()->id;
},
'color_id' => function() {
return Color::factory()->create()->id;
},
'user_id' => function() {
return User::factory()->create()->id;
}
];
}
}
================================================
FILE: tests/Database/Factories/ColorFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Color;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AjCastro\EagerLoadPivotRelations\Tests\Models\Color>
*/
class ColorFactory extends Factory
{
protected $model = Color::class;
public function definition()
{
return [
'name' => $this->faker->word,
];
}
}
================================================
FILE: tests/Database/Factories/TireFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Tire;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AjCastro\EagerLoadPivotRelations\Tests\Models\Tire>
*/
class TireFactory extends Factory
{
protected $model = Tire::class;
public function definition()
{
return [
'brand' => $this->faker->word,
'profile_depth' => $this->faker->randomNumber(2),
'car_user_id' => function()
{
return CarUser::factory()->create()->id;
}
];
}
}
================================================
FILE: tests/Database/Factories/UserFactory.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Database\Factories;
use AjCastro\EagerLoadPivotRelations\Tests\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\AjCastro\EagerLoadPivotRelations\Tests\Models\User>
*/
class UserFactory extends Factory
{
protected $model = User::class;
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
================================================
FILE: tests/Database/Migrations/2014_10_12_000000_create_users_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
================================================
FILE: tests/Database/Migrations/2014_10_12_100000_create_password_resets_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}
================================================
FILE: tests/Database/Migrations/2019_06_02_131048_create_brands_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBrandsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('brands', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('logo');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('brands');
}
}
================================================
FILE: tests/Database/Migrations/2019_06_02_131049_create_cars_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cars', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('model');
$table->bigInteger('brand_id');
$table->foreign('brand_id')->references('id')->on('brands')->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cars');
}
}
================================================
FILE: tests/Database/Migrations/2019_06_02_131100_create_colors_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateColorsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('colors', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('colors');
}
}
================================================
FILE: tests/Database/Migrations/2019_06_02_131120_create_car_user_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCarUserTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('car_user', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('car_id');
$table->foreign('car_id')->references('id')->on('cars')->cascadeOnDelete();
$table->unsignedBigInteger('color_id');
$table->foreign('color_id')->references('id')->on('colors')->cascadeOnDelete();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('car_user');
}
}
================================================
FILE: tests/Database/Migrations/2019_06_02_131148_create_tires_table.php
================================================
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTiresTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tires', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('brand');
$table->integer('profile_depth');
$table->bigInteger('car_user_id');
$table->foreign('car_user_id')->references('id')->on('car_user')->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tires');
}
}
================================================
FILE: tests/Models/Brand.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\BrandFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
use HasFactory;
protected $table = 'brands';
protected $fillable = [
'name',
'logo'
];
public function cars()
{
return $this->hasMany(Car::class);
}
protected static function newFactory()
{
return BrandFactory::new();
}
}
================================================
FILE: tests/Models/Car.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\EagerLoadPivotTrait;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\CarFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $model
* @property string $make
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \AjCastro\EagerLoadPivotRelations\Tests\Models\User[]|null $users
* @method static \AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\CarFactory factory(...$parameters)
* @method static Builder|Car newModelQuery()
* @method static Builder|Car newQuery()
* @method static Builder|Car query()
* @mixin \Eloquent
*/
class Car extends Model
{
use EagerLoadPivotTrait;
use HasFactory;
protected $table = 'cars';
protected $fillable = [
'model',
'brand_id',
];
public function brand()
{
return $this->belongsTo(Brand::class);
}
public function users()
{
return $this->belongsToMany(User::class)
->withPivot('color_id')
->using(CarUser::class)
->as('car_user');
}
protected static function newFactory()
{
return CarFactory::new();
}
}
================================================
FILE: tests/Models/CarUser.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\CarUserFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* @property int $id
* @property int $car_id
* @property int $color_id
* @property int $user_id
* @property-read \AjCastro\EagerLoadPivotRelations\Tests\Models\Car|null $car
* @property-read \AjCastro\EagerLoadPivotRelations\Tests\Models\Color|null $color
* @property-read \AjCastro\EagerLoadPivotRelations\Tests\Models\User|null $user
* @method static \AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\CarUserFactory factory(...$parameters)
* @method static Builder|CarUser newModelQuery()
* @method static Builder|CarUser newQuery()
* @method static Builder|CarUser query()
* @mixin \Eloquent
*/
class CarUser extends Pivot
{
use HasFactory;
public $incrementing = true;
protected $table = 'car_user';
protected $fillable = [
'car_id',
'color_id',
'user_id'
];
public function car()
{
return $this->belongsTo(Car::class);
}
public function color()
{
return $this->belongsTo(Color::class);
}
public function tires()
{
return $this->hasMany(Tire::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
protected static function newFactory()
{
return CarUserFactory::new();
}
}
================================================
FILE: tests/Models/Color.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\ColorFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $name
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\ColorFactory factory(...$parameters)
* @method static Builder|Color newModelQuery()
* @method static Builder|Color newQuery()
* @method static Builder|Color query()
* @mixin \Eloquent
*/
class Color extends Model
{
use HasFactory;
protected $table = 'colors';
protected $fillable = [
'name'
];
public function cars()
{
return $this->belongsToMany(Car::class);
}
public function users()
{
return $this->belongsToMany(User::class);
}
protected static function newFactory()
{
return ColorFactory::new();
}
}
================================================
FILE: tests/Models/Tire.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\TireFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property string $brand
* @property int $profile_depth
* @property int $car_user_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\TireFactory factory(...$parameters)
* @method static Builder|Tire newModelQuery()
* @method static Builder|Tire newQuery()
* @method static Builder|Tire query()
* @mixin \Eloquent
*/
class Tire extends Model
{
use HasFactory;
protected $table = 'tires';
protected $fillable = [
'brand',
'profile_depth',
'car_user_id',
];
protected static function newFactory()
{
return TireFactory::new();
}
}
================================================
FILE: tests/Models/User.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Models;
use AjCastro\EagerLoadPivotRelations\EagerLoadPivotTrait;
use AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* @property int $id
* @property string $name
* @property string $email
* @property string $password
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \AjCastro\EagerLoadPivotRelations\Tests\Database\Factories\UserFactory factory(...$parameters)
* @method static Builder|User newModelQuery()
* @method static Builder|User newQuery()
* @method static Builder|User query()
* @mixin \Illuminate\Database\Eloquent
*/
class User extends Authenticatable
{
use HasFactory;
use EagerLoadPivotTrait;
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function cars()
{
return $this->belongsToMany(Car::class)
->withPivot('color_id')
->using(CarUser::class);
}
protected static function newFactory()
{
return UserFactory::new();
}
}
================================================
FILE: tests/TestCase.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests;
use Orchestra\Testbench\TestCase as BaseTestCase;
class TestCase extends BaseTestCase
{
protected function setUp(): void
{
parent::setUp();
}
protected function getPackageProviders($app)
{
}
protected function getEnvironmentSetUp($app)
{
( new \CreateUsersTable )->up();
( new \CreatePasswordResetsTable )->up();
( new \CreateBrandsTable )->up();
( new \CreateCarsTable )->up();
( new \CreateColorsTable )->up();
( new \CreateCarUserTable )->up();
( new \CreateTiresTable )->up();
}
}
================================================
FILE: tests/Unit/CountTest.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Unit;
use AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Tire;
use AjCastro\EagerLoadPivotRelations\Tests\Models\User;
use AjCastro\EagerLoadPivotRelations\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class CountTest extends TestCase
{
use RefreshDatabase;
public function test_it_can_use_with_count_pivot_relations()
{
$this->markTestSkipped('This could be a new feature, see #6');
$user = User::factory()->create();
$pivots = CarUser::factory( [ 'user_id' => $user->id ] )->count( 2 )->create();
$tires = rand(4, 8);
foreach($pivots as $pivot) {
Tire::factory(['car_user_id' => $pivot->id])
->count($tires)
->create();
}
$user = User::with( [
'cars',
'cars.pivot.color',
'cars.pivot' => function($query) {
return $query->withCount('tires');
}
] )
->find( $user->id );
$this->assertSame($tires, $user->cars[0]->pivot->tires_count);
}
public function test_it_can_use_load_count_pivot_relations()
{
$this->markTestSkipped('This could be a new feature, see #6');
$user = User::factory()->create();
$pivots = CarUser::factory( [ 'user_id' => $user->id ] )->count( 2 )->create();
$tires = rand(4, 8);
foreach($pivots as $pivot) {
Tire::factory(['car_user_id' => $pivot->id])
->count($tires)
->create();
}
$user = User::find($user->id);
$user->load([
'cars',
'cars.pivot.color',
'cars.pivot' => function($query) {
return $query->withCount('tires');
}]);
$this->assertSame($tires, $user->cars[0]->pivot->tires_count);
}
}
================================================
FILE: tests/Unit/PaginateTest.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Unit;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Car;
use AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser;
use AjCastro\EagerLoadPivotRelations\Tests\Models\User;
use AjCastro\EagerLoadPivotRelations\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Pagination\LengthAwarePaginator;
class PaginateTest extends TestCase
{
use RefreshDatabase;
public function test_it_can_paginate_with_pivot_relations()
{
$pivots = CarUser::factory()->count( 30 )->create();
$users = User::with([
'cars',
'cars.pivot.color'
])
->paginate(10);
$this->assertInstanceOf(LengthAwarePaginator::class, $users);
}
public function test_it_can_paginate_after_eager_loading_pivot_relations()
{
$this->markTestSkipped('Failing see #3');
$pivots = CarUser::factory()->count( 30 )->create();
$user = User::find(1)->cars()->with(['pivot.color'])->paginate(10);
$this->assertInstanceOf(LengthAwarePaginator::class, $user);
}
public function test_it_can_paginate_with_custom_pivot_relations()
{
$pivots = CarUser::factory()->count( 30 )->create();
$cars = Car::with([
'users',
'users.car_user.color'
])
->paginate(10);
$this->assertInstanceOf(LengthAwarePaginator::class, $cars);
}
public function test_it_can_paginate_after_eager_loading_custom_pivot_relations()
{
$this->markTestSkipped('Failing see #3');
$pivots = CarUser::factory()->count( 30 )->create();
$car = Car::find(1)->users()->with(['car_user.color'])->paginate(10);
$this->assertInstanceOf(LengthAwarePaginator::class, $car);
}
}
================================================
FILE: tests/Unit/PivotTest.php
================================================
<?php
namespace AjCastro\EagerLoadPivotRelations\Tests\Unit;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Car;
use AjCastro\EagerLoadPivotRelations\Tests\Models\CarUser;
use AjCastro\EagerLoadPivotRelations\Tests\Models\Color;
use AjCastro\EagerLoadPivotRelations\Tests\Models\User;
use AjCastro\EagerLoadPivotRelations\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class PivotTest extends TestCase
{
use RefreshDatabase;
public function test_it_can_use_with_pivot_relations()
{
$user = User::factory()->create();
$pivots = CarUser::factory(['user_id' => $user->id])->count( 2 )->create();
$user = User::with([
'cars',
'cars.pivot.color'
])
->find($user->id);
$this->assertInstanceOf(Car::class, $user->cars[0]);
$this->assertInstanceOf(Color::class, $user->cars[0]->pivot->color);
}
public function test_it_can_use_load_pivot_relations()
{
$user = User::factory()->create();
$pivots = CarUser::factory(['user_id' => $user->id])->count( 2 )->create();
$user->load([
'cars',
'cars.pivot.color'
]);
$this->assertInstanceOf(Car::class, $user->cars[0]);
$this->assertInstanceOf(Color::class, $user->cars[0]->pivot->color);
}
public function test_it_can_use_load_missing_pivot_relations()
{
$user = User::factory()->create();
$pivots = CarUser::factory(['user_id' => $user->id])->count( 2 )->create();
$user->loadMissing([
'cars',
'cars.pivot.color'
]);
$this->assertInstanceOf(Car::class, $user->cars[0]);
$this->assertInstanceOf(Color::class, $user->cars[0]->pivot->color);
}
public function test_it_can_use_with_custom_pivot_relations()
{
$car = Car::factory()->create();
$pivots = CarUser::factory(['car_id' => $car->id])->count( 2 )->create();
$car = Car::with([
'users',
'users.car_user.color'
])
->find($car->id);
$this->assertInstanceOf(User::class, $car->users[0]);
$this->assertInstanceOf(Color::class, $car->users[0]->car_user->color);
}
public function test_it_can_use_load_custom_pivot_relations()
{
$car = Car::factory()->create();
$pivots = CarUser::factory(['car_id' => $car->id])->count( 2 )->create();
$car->load([
'users',
'users.car_user.color'
]);
$this->assertInstanceOf(User::class, $car->users[0]);
$this->assertInstanceOf(Color::class, $car->users[0]->car_user->color);
}
public function test_it_can_use_load_missing_custom_pivot_relations()
{
$car = Car::factory()->create();
$pivots = CarUser::factory(['car_id' => $car->id])->count( 2 )->create();
$car->loadMissing([
'users',
'users.car_user.color'
]);
$this->assertInstanceOf(User::class, $car->users[0]);
$this->assertInstanceOf(Color::class, $car->users[0]->car_user->color);
}
}
gitextract__wxmb_sj/
├── .gitattributes
├── .github/
│ └── workflows/
│ └── tests.yml
├── .gitignore
├── README.md
├── composer.json
├── phpunit.xml.dist
├── src/
│ ├── EagerLoadPivotBuilder.php
│ └── EagerLoadPivotTrait.php
└── tests/
├── Database/
│ ├── Factories/
│ │ ├── BrandFactory.php
│ │ ├── CarFactory.php
│ │ ├── CarUserFactory.php
│ │ ├── ColorFactory.php
│ │ ├── TireFactory.php
│ │ └── UserFactory.php
│ └── Migrations/
│ ├── 2014_10_12_000000_create_users_table.php
│ ├── 2014_10_12_100000_create_password_resets_table.php
│ ├── 2019_06_02_131048_create_brands_table.php
│ ├── 2019_06_02_131049_create_cars_table.php
│ ├── 2019_06_02_131100_create_colors_table.php
│ ├── 2019_06_02_131120_create_car_user_table.php
│ └── 2019_06_02_131148_create_tires_table.php
├── Models/
│ ├── Brand.php
│ ├── Car.php
│ ├── CarUser.php
│ ├── Color.php
│ ├── Tire.php
│ └── User.php
├── TestCase.php
└── Unit/
├── CountTest.php
├── PaginateTest.php
└── PivotTest.php
SYMBOL INDEX (82 symbols across 25 files)
FILE: src/EagerLoadPivotBuilder.php
class EagerLoadPivotBuilder (line 11) | class EagerLoadPivotBuilder extends Builder
method eagerLoadRelation (line 26) | protected function eagerLoadRelation(array $models, $name, Closure $co...
method watchForPivotAccessors (line 44) | protected function watchForPivotAccessors($name)
method isPivotAccessor (line 65) | protected function isPivotAccessor($name)
method eagerLoadPivotRelations (line 77) | protected function eagerLoadPivotRelations($models, $pivotAccessor)
method getPivotEagerLoadRelations (line 90) | protected function getPivotEagerLoadRelations($pivotAccessor)
FILE: src/EagerLoadPivotTrait.php
type EagerLoadPivotTrait (line 5) | trait EagerLoadPivotTrait
method newEloquentBuilder (line 13) | public function newEloquentBuilder($query)
FILE: tests/Database/Factories/BrandFactory.php
class BrandFactory (line 8) | class BrandFactory extends Factory
method definition (line 12) | public function definition()
FILE: tests/Database/Factories/CarFactory.php
class CarFactory (line 12) | class CarFactory extends Factory
method definition (line 16) | public function definition()
FILE: tests/Database/Factories/CarUserFactory.php
class CarUserFactory (line 15) | class CarUserFactory extends Factory
method definition (line 19) | public function definition()
FILE: tests/Database/Factories/ColorFactory.php
class ColorFactory (line 11) | class ColorFactory extends Factory
method definition (line 15) | public function definition()
FILE: tests/Database/Factories/TireFactory.php
class TireFactory (line 12) | class TireFactory extends Factory
method definition (line 16) | public function definition()
FILE: tests/Database/Factories/UserFactory.php
class UserFactory (line 12) | class UserFactory extends Factory
method definition (line 16) | public function definition()
FILE: tests/Database/Migrations/2014_10_12_000000_create_users_table.php
class CreateUsersTable (line 7) | class CreateUsersTable extends Migration
method up (line 14) | public function up()
method down (line 32) | public function down()
FILE: tests/Database/Migrations/2014_10_12_100000_create_password_resets_table.php
class CreatePasswordResetsTable (line 7) | class CreatePasswordResetsTable extends Migration
method up (line 14) | public function up()
method down (line 28) | public function down()
FILE: tests/Database/Migrations/2019_06_02_131048_create_brands_table.php
class CreateBrandsTable (line 7) | class CreateBrandsTable extends Migration
method up (line 14) | public function up()
method down (line 29) | public function down()
FILE: tests/Database/Migrations/2019_06_02_131049_create_cars_table.php
class CreateCarsTable (line 7) | class CreateCarsTable extends Migration
method up (line 14) | public function up()
method down (line 32) | public function down()
FILE: tests/Database/Migrations/2019_06_02_131100_create_colors_table.php
class CreateColorsTable (line 7) | class CreateColorsTable extends Migration
method up (line 14) | public function up()
method down (line 28) | public function down()
FILE: tests/Database/Migrations/2019_06_02_131120_create_car_user_table.php
class CreateCarUserTable (line 7) | class CreateCarUserTable extends Migration
method up (line 14) | public function up()
method down (line 37) | public function down()
FILE: tests/Database/Migrations/2019_06_02_131148_create_tires_table.php
class CreateTiresTable (line 7) | class CreateTiresTable extends Migration
method up (line 14) | public function up()
method down (line 33) | public function down()
FILE: tests/Models/Brand.php
class Brand (line 9) | class Brand extends Model
method cars (line 19) | public function cars()
method newFactory (line 24) | protected static function newFactory()
FILE: tests/Models/Car.php
class Car (line 26) | class Car extends Model
method brand (line 37) | public function brand()
method users (line 42) | public function users()
method newFactory (line 50) | protected static function newFactory()
FILE: tests/Models/CarUser.php
class CarUser (line 24) | class CarUser extends Pivot
method car (line 36) | public function car()
method color (line 41) | public function color()
method tires (line 46) | public function tires()
method user (line 51) | public function user()
method newFactory (line 56) | protected static function newFactory()
FILE: tests/Models/Color.php
class Color (line 21) | class Color extends Model
method cars (line 30) | public function cars()
method users (line 35) | public function users()
method newFactory (line 40) | protected static function newFactory()
FILE: tests/Models/Tire.php
class Tire (line 23) | class Tire extends Model
method newFactory (line 34) | protected static function newFactory()
FILE: tests/Models/User.php
class User (line 24) | class User extends Authenticatable
method cars (line 57) | public function cars()
method newFactory (line 64) | protected static function newFactory()
FILE: tests/TestCase.php
class TestCase (line 6) | class TestCase extends BaseTestCase
method setUp (line 8) | protected function setUp(): void
method getPackageProviders (line 13) | protected function getPackageProviders($app)
method getEnvironmentSetUp (line 17) | protected function getEnvironmentSetUp($app)
FILE: tests/Unit/CountTest.php
class CountTest (line 11) | class CountTest extends TestCase
method test_it_can_use_with_count_pivot_relations (line 15) | public function test_it_can_use_with_count_pivot_relations()
method test_it_can_use_load_count_pivot_relations (line 41) | public function test_it_can_use_load_count_pivot_relations()
FILE: tests/Unit/PaginateTest.php
class PaginateTest (line 12) | class PaginateTest extends TestCase
method test_it_can_paginate_with_pivot_relations (line 16) | public function test_it_can_paginate_with_pivot_relations()
method test_it_can_paginate_after_eager_loading_pivot_relations (line 29) | public function test_it_can_paginate_after_eager_loading_pivot_relatio...
method test_it_can_paginate_with_custom_pivot_relations (line 39) | public function test_it_can_paginate_with_custom_pivot_relations()
method test_it_can_paginate_after_eager_loading_custom_pivot_relations (line 52) | public function test_it_can_paginate_after_eager_loading_custom_pivot_...
FILE: tests/Unit/PivotTest.php
class PivotTest (line 12) | class PivotTest extends TestCase
method test_it_can_use_with_pivot_relations (line 16) | public function test_it_can_use_with_pivot_relations()
method test_it_can_use_load_pivot_relations (line 31) | public function test_it_can_use_load_pivot_relations()
method test_it_can_use_load_missing_pivot_relations (line 45) | public function test_it_can_use_load_missing_pivot_relations()
method test_it_can_use_with_custom_pivot_relations (line 59) | public function test_it_can_use_with_custom_pivot_relations()
method test_it_can_use_load_custom_pivot_relations (line 74) | public function test_it_can_use_load_custom_pivot_relations()
method test_it_can_use_load_missing_custom_pivot_relations (line 88) | public function test_it_can_use_load_missing_custom_pivot_relations()
Condensed preview — 31 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (39K chars).
[
{
"path": ".gitattributes",
"chars": 305,
"preview": "/.editorconfig export-ignore\n/.gitattributes export-ignore\n/.gitignore export-ignore\n/.github "
},
{
"path": ".github/workflows/tests.yml",
"chars": 1005,
"preview": "name: Tests\n\non:\n pull_request:\n push:\n branches: [master, main]\n\njobs:\n test:\n runs-on: ubuntu-20.04\n strat"
},
{
"path": ".gitignore",
"chars": 29,
"preview": "/vendor\ncomposer.lock\n*.cache"
},
{
"path": "README.md",
"chars": 3753,
"preview": "# Laravel Eloquent: Eager Load Pivot Relations\n\nEager load pivot relations for Laravel Eloquent's BelongsToMany relation"
},
{
"path": "composer.json",
"chars": 1014,
"preview": "{\n \"name\": \"ajcastro/eager-load-pivot-relations\",\n \"description\": \"Eager load pivot relations for Laravel Eloquent"
},
{
"path": "phpunit.xml.dist",
"chars": 1197,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n bootstrap"
},
{
"path": "src/EagerLoadPivotBuilder.php",
"chars": 2789,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations;\n\nuse Closure;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMan"
},
{
"path": "src/EagerLoadPivotTrait.php",
"chars": 390,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations;\n\ntrait EagerLoadPivotTrait\n{\n /**\n * Create a new Eloquent que"
},
{
"path": "tests/Database/Factories/BrandFactory.php",
"chars": 425,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Factories/CarFactory.php",
"chars": 690,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Factories/CarUserFactory.php",
"chars": 1014,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Factories/ColorFactory.php",
"chars": 501,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Factories/TireFactory.php",
"chars": 743,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Factories/UserFactory.php",
"chars": 776,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Factories;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\"
},
{
"path": "tests/Database/Migrations/2014_10_12_000000_create_users_table.php",
"chars": 820,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2014_10_12_100000_create_password_resets_table.php",
"chars": 683,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2019_06_02_131048_create_brands_table.php",
"chars": 671,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2019_06_02_131049_create_cars_table.php",
"chars": 768,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2019_06_02_131100_create_colors_table.php",
"chars": 635,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2019_06_02_131120_create_car_user_table.php",
"chars": 1031,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Database/Migrations/2019_06_02_131148_create_tires_table.php",
"chars": 824,
"preview": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Fa"
},
{
"path": "tests/Models/Brand.php",
"chars": 561,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Fac"
},
{
"path": "tests/Models/Car.php",
"chars": 1425,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\EagerLoadPivotTrai"
},
{
"path": "tests/Models/CarUser.php",
"chars": 1564,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Fac"
},
{
"path": "tests/Models/Color.php",
"chars": 1119,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Fac"
},
{
"path": "tests/Models/Tire.php",
"chars": 1044,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Database\\Fac"
},
{
"path": "tests/Models/User.php",
"chars": 1738,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Models;\n\nuse AjCastro\\EagerLoadPivotRelations\\EagerLoadPivotTrai"
},
{
"path": "tests/TestCase.php",
"chars": 644,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests;\nuse Orchestra\\Testbench\\TestCase as BaseTestCase;\n\nclass TestCa"
},
{
"path": "tests/Unit/CountTest.php",
"chars": 1963,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Unit;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Models\\CarUser"
},
{
"path": "tests/Unit/PaginateTest.php",
"chars": 1827,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Unit;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Models\\Car;\nus"
},
{
"path": "tests/Unit/PivotTest.php",
"chars": 3135,
"preview": "<?php\n\nnamespace AjCastro\\EagerLoadPivotRelations\\Tests\\Unit;\n\nuse AjCastro\\EagerLoadPivotRelations\\Tests\\Models\\Car;\nus"
}
]
About this extraction
This page contains the full source code of the ajcastro/eager-load-pivot-relations GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 31 files (34.3 KB), approximately 9.4k tokens, and a symbol index with 82 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.