onelearningcommunity/laravel-model-explorer
Installation:
composer require onelearningcommunity/laravel-model-explorer
No additional configuration or publishing is required.
Access the Tool:
/model-explorer in your browser (e.g., http://localhost:8000/model-explorer).First Use Case:
Debugging Relationships:
dd() or toArray() calls during development.belongsToMany relationship:
Onboarding New Developers:
/model-explorer URL during code reviews or pair programming to quickly familiarize team members with the schema and model logic.Dynamic Data Exploration:
email and expand their posts relationship to verify data integrity.Schema Documentation:
/model-explorer route in your IDE or browser for quick reference.Integration with Testing:
full_name accessors) against expected values.Customizing the Explorer:
vendor:publish --provider="OneLearningCommunity\ModelExplorer\ModelExplorerServiceProvider" if needed).ModelExplorerController.API-Driven Exploration:
/api/models, /api/models/{model}/records). Use these in custom admin panels or CLI tools.$records = Http::get("http://localhost:8000/api/models/{$modelClass}/records");
Performance Profiling:
hasManyThrough or morphTo relationships.Seeding Validation:
Excluded Models:
app/Models namespace by default. To include them, add the namespace to the discoverModels config:
'namespaces' => [
'App\Models',
'App\\Other\\Namespace', // Add custom namespaces here
],
config/model-explorer.php file for excluded namespaces or models.Performance with Large Datasets:
limit query parameter (e.g., /model-explorer/records?model=App\Models\User&limit=10) or filter by a unique field (e.g., ?field=email&value=test@example.com).Caching Issues:
php artisan cache:clear
php artisan config:clear
Polymorphic Relationships:
morphTo) may not display foreign key details clearly in the UI. Manually verify these in the database or by inspecting the raw attributes of a record.Hidden or Guarded Attributes:
hidden or guarded in the model may not appear in the "Record lookup" view. Use the "Model detail" tab to confirm which attributes are excluded.Localization or Translation Issues:
translatable package), the explorer may not display translated attributes dynamically. Stick to base attributes or use the raw data view.Check the Logs:
APP_DEBUG=true) to see any errors or warnings in the Laravel log (storage/logs/laravel.log). Common issues include:
Inspect Raw Data:
Verify Relationship Types:
Test with a Fresh Instance:
Custom Filters:
ModelExplorerController to add custom filters or actions. For example, add a "Soft Deletes" toggle to the record lookup:
// app/Http/Controllers/ModelExplorerController.php
public function records(Request $request, string $model)
{
$query = ModelExplorer::query($model);
if ($request->has('with_deleted')) {
$query->withDeleted();
}
return $query->get();
}
Add Custom Tabs:
ModelExplorerServiceProvider to register additional tabs or views. For example, add a "Model Events" tab to display registered listeners:
// app/Providers/ModelExplorerServiceProvider.php
public function boot()
{
ModelExplorer::extend(function ($explorer) {
$explorer->addTab('events', function ($model) {
return view('model-explorer::tabs.events', ['model' => $model]);
});
});
}
Modify Record Display:
resources/views/vendor/model-explorer/partials/record.blade.php) to customize how records are rendered. For example, add syntax highlighting to accessor snippets.API Extensions:
/api/models endpoint to include custom metadata. For example, add a hasSoftDeletes field:
// app/Http/Controllers/ModelExplorerController.php
public function apiModels()
{
return ModelExplorer::all()->map(function ($model) {
return array_merge($model->toArray(), [
'has_soft_deletes' => in_array(\Illuminate\Database\Eloquent\SoftDeletes::class, class_uses_recursive($model->getModel())),
]);
});
}
Environment-Specific Configuration:
// config/model-explorer.php
'enabled' => env('MODEL_EXPLORER_ENABLED', false),
MODEL_EXPLORER_ENABLED=true in your .env for local development.How can I help you explore Laravel packages today?