-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from LiborStransky/master
Add Model panel
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<style class="tracy-debug"> | ||
#tracy-debug td.Laravel-DatabasePanel-sql { background: white !important } | ||
#tracy-debug .Laravel-DatabasePanel-source { color: #BBB !important } | ||
#tracy-debug .Laravel-DatabasePanel-hint code { color:#f00!important } | ||
#tracy-debug .Laravel-DatabasePanel-hint { margin-top: 15px } | ||
#tracy-debug .Laravel-DatabasePanel-explain { margin-top: 15px } | ||
</style> | ||
|
||
<h1>Models: <?php echo $total ?></h1> | ||
|
||
<div class="tracy-inner"> | ||
<div class="tracy-inner-container"> | ||
<table> | ||
<tr> | ||
<th>Model Name</th> | ||
<th>Count</th> | ||
</tr> | ||
<?php foreach ($models as $name => $count) { ?> | ||
<tr> | ||
<td> | ||
<?php echo $name; ?> | ||
</td> | ||
<td> | ||
<?php echo $count; ?> | ||
</td> | ||
</tr> | ||
<?php } ?> | ||
</table> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<span title="Model"> | ||
<span class="tracy-label"> | ||
<?php echo 'Models:'.$total ?> | ||
</span> | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Recca0120\LaravelTracy\Panels; | ||
|
||
use Illuminate\Support\Str; | ||
use Recca0120\LaravelTracy\Contracts\IAjaxPanel; | ||
|
||
class ModelPanel extends AbstractSubscriablePanel implements IAjaxPanel | ||
{ | ||
/** | ||
* $models. | ||
* | ||
* @var array | ||
*/ | ||
protected $models = []; | ||
|
||
/** | ||
* $total number of models. | ||
* | ||
* @var int | ||
*/ | ||
protected $total = 0; | ||
|
||
/** | ||
* subscribe. | ||
*/ | ||
protected function subscribe() | ||
{ | ||
$events = $this->laravel['events']; | ||
$events->listen('eloquent.*', function ($event, $models) { | ||
if (Str::contains($event, 'eloquent.retrieved')) { | ||
foreach ($models as $model) { | ||
$class = get_class($model); | ||
$this->models[$class] = ($this->models[$class] ?? 0) + 1; | ||
$this->total++; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* getAttributes. | ||
* | ||
* @return array | ||
*/ | ||
protected function getAttributes() | ||
{ | ||
return [ | ||
'total' => $this->total, | ||
'models' => $this->models, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters