Eloquent Inspector for Laravel
This package provides helpful information about the use
statements of a model, model properties, and model relationships:
1 2// All `use` statements for a model 3$useStatements = Inspector::inspect(User::class)->getUseStatements(); 4/* 5[ 6 'Model' => 'Illuminate\Database\Eloquent\Model', 7 'Baz' => 'Foo\Bar', 8] 9*/10 11 12// Model properties13$properties = Inspector::inspect(User::class)->getProperties();14 15$properties['id']->name; // id16$properties['id']->type; // int17$properties['id']->dbType; // integer18$properties['id']->nullable; // false19$properties['id']->default; // null20 21 22$relationships = Inspector::inspect(User::class)->getRelationships();23 24$relationships['posts']->name; // posts25$relationships['posts']->type; // hasMany26// Illuminate\Database\Eloquent\Relations\HasMany27$relationships['posts']->class;28$relationships['posts']->model; // App\Models\Post29$relationships['posts']->relatesToMany; // true
Model relationships and properties return an array, with the key being the property/relationship name and the value being an object with detailed information about that property/relationship.
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
0 comments:
Post a Comment
Thanks