PHP code example of norewrite / laravel-unused-eager-loads

1. Go to this page and download the library: Download norewrite/laravel-unused-eager-loads 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/ */

    

norewrite / laravel-unused-eager-loads example snippets


$boats = Boat::with('serviceLocations')->get();

return response()->json($boats);

$boat->serviceLocations



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use NoRewrite\UnusedEagerLoads\Concerns\TracksRelationshipUsage;

abstract class BaseModel extends Model
{
    use TracksRelationshipUsage;
}

use NoRewrite\UnusedEagerLoads\Concerns\TracksRelationshipUsage;

class Boat extends Model
{
    use TracksRelationshipUsage;
}

$boats = Boat::with('serviceLocations')->get();

return view('boats.index', compact('boats'));

$boat->serviceLocations

$boats = Boat::with('serviceLocations')->get();

$articles = Article::with('comments.author')->get();

$article->comments

$comment->author

$post = Post::first();

echo $post->author->name;

$model->toArray();
$model->toJson();

return response()->json($model);

'enabled' => env('UNUSED_EAGER_LOADS_ENABLED', false),

'reporting' => [
    'unused_level' => 'warning',

    'serialization_only_level' => 'info',

    'partial_level' => 'debug',

    'report_serialization_only' => true,

    'report_partial' => false,

    'minimum_loaded' => 1,

    'report_on_error_responses' => false,
],

'ignore' => [
    'models' => [
        'App\\Models\\Audit*',
    ],

    'relations' => [
        'pivot',
        'media',
    ],

    'paths' => [
        '*.internalMetadata',
    ],
],

$model->relation

$model->author;

$model->getRelation('author');
bash
php artisan vendor:publish --tag=unused-eager-loads-config
text
config/unused-eager-loads.php
text
comments.author
text
serialization_only