PHP code example of cerbero / eloquent-inspector

1. Go to this page and download the library: Download cerbero/eloquent-inspector 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/ */

    

cerbero / eloquent-inspector example snippets


use App\Models\User;
use Cerbero\EloquentInspector\Inspector;

$inspector = Inspector::inspect(User::class);

// flush information of all inspected models
Inspector::flush();

// flush information of an inspected model
Inspector::flush(User::class);

// forget information of the current inspection
Inspector::inspect(User::class)->forget();

$model = Inspector::inspect(User::class)->getModel(); // App\Models\User

use Illuminate\Database\Eloquent\Model;
use Foo\Bar as Baz;

class User extends Model
{
    // ...
}

$useStatements = Inspector::inspect(User::class)->getUseStatements();
/*
[
    'Model' => 'Illuminate\Database\Eloquent\Model',
    'Baz' => 'Foo\Bar',
]
*/

$properties = Inspector::inspect(User::class)->getProperties();
/*
[
    'id' => <Cerbero\EloquentInspector\Dtos\Property>,
    'name' => <Cerbero\EloquentInspector\Dtos\Property>,
    ...
]
*/

$properties['id']->name; // id
$properties['id']->type; // int
$properties['id']->dbType; // integer
$properties['id']->nullable; // false
$properties['id']->default; // null

$relationships = Inspector::inspect(User::class)->getRelationships();
/*
[
    'posts' => <Cerbero\EloquentInspector\Dtos\Relationship>,
    'tags' => <Cerbero\EloquentInspector\Dtos\Relationship>,
    ...
]
*/

$relationships['posts']->name; // posts
$relationships['posts']->type; // hasMany
$relationships['posts']->class; // Illuminate\Database\Eloquent\Relations\HasMany
$relationships['posts']->model; // App\Models\Post
$relationships['posts']->relatesToMany; // true