PHPackages                             mpociot/cockpit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. mpociot/cockpit

ActiveLibrary[Admin Panels](/categories/admin)

mpociot/cockpit
===============

0.9.0(10y ago)393122MITPHPPHP &gt;=5.3.0

Since Nov 4Pushed 10y ago2 watchersCompare

[ Source](https://github.com/mpociot/cockpit)[ Packagist](https://packagist.org/packages/mpociot/cockpit)[ Docs](http://github.com/mpociot/cockpit)[ RSS](/packages/mpociot-cockpit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Cockpit
=======

[](#cockpit)

Custom widgets for your Laravel app
-----------------------------------

[](#custom-widgets-for-your-laravel-app)

[![image](https://camo.githubusercontent.com/ed7b1a7fdc8dcc75618faa7bf0a66aae3700a362e20c81cec1a0635cfd5b421e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/ed7b1a7fdc8dcc75618faa7bf0a66aae3700a362e20c81cec1a0635cfd5b421e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)[![image](https://camo.githubusercontent.com/1cab2e4872febbc5f98fea2441642c6612860983e9fb6333ca179a5027814cf5/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/1cab2e4872febbc5f98fea2441642c6612860983e9fb6333ca179a5027814cf5/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)[![image](https://camo.githubusercontent.com/774e14817bb84d343976671a0e289c2757a64c1a874d5ed8b7c2ed6b7551a240/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/774e14817bb84d343976671a0e289c2757a64c1a874d5ed8b7c2ed6b7551a240/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d706f63696f742f636f636b7069742e7376673f7374796c653d666c6174)[![codecov.io](https://camo.githubusercontent.com/dc9999ae37c35840fcb14ba1a6fed358f1ac4d42077bbd559a80c0bbe8559711/68747470733a2f2f636f6465636f762e696f2f6769746875622f6d706f63696f742f636f636b7069742f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/mpociot/cockpit?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cef830a983f1163e7a802b4d447eda749c5a9f3b4631458ed4262db145eb357b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d706f63696f742f636f636b7069742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpociot/cockpit/?branch=master)[![Build Status](https://camo.githubusercontent.com/4cd64bdc4c4c82489c88f1587f40ae35d8d7e6311ac6ecc1728f2851ef51bf4d/68747470733a2f2f7472617669732d63692e6f72672f6d706f63696f742f636f636b7069742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mpociot/cockpit)

[![](./documentation/cockpit.png)](./documentation/cockpit.png)

Easy to use widgets with custom metrics, filters and drag and drop support.

**Note:** Documentation is still in progress.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Custom metrics](#metrics)
    - [How does it work?](#how-it-works)
    - [Custom filters](#filters)
    - [Available chart types](#chart-types)
- [License](#license)

\## Installation In order to install Cockpit, just add

```
"mpociot/cockpit": "~1.0"

```

to your composer.json. Then run `composer install` or `composer update`.

(or run `composer require mpociot/cockpit` if you prefere that)

Then in your `config/app.php` add

```
Mpociot\Cockpit\CockpitServiceProvider::class

```

in the `providers` array.

Next, publish Cockpit's views, javascript files and migration and run the migrate command.

```
php artisan vendor:publish --provider="Mpociot\Cockpit\CockpitServiceProvider"
php artisan migrate
```

\## Usage After you've published all the needed assets and created the `widgets` table through the Cockpit migration, you're good to go.

Cockpit comes with some preconfigured routes, so go ahead and visit: `http://your.app/cockpit/`.

This is your "dashboard" which allows you to create custom widgets that will query your application and show some nice charts.

\### How does it work? When you add a new widget, Cockpit will look in a configurable folder for all available metrics your app could define. Each metric can have multiple sub-metrics that can be queried and those sub-metrics are filterable.

Example to make the concept easier to understand:

Your app logs all logins. On your dashboard, you want to be able to show a widget that displays:

- All logins grouped by "time" (this could be day, week, month, year)
- All logins grouped by specific users

In this case, your metric would be `Logins` that has two submetrics named `per_time` and `per_user`.

\### Custom metrics ![](./documentation/widget_configuration.png)Cockpit ships a simple `Users` metric, which will be copied to this directory: `app/Cockpit/Metrics`. If your app is running in a different namespace or you want to change the path of your custom metrics, modify the appropriate values in the `config/cockpit.php` file.

The base structure of a metric is:

```
use Mpociot\Cockpit\Metric;

class Logins extends Metric
{
	// Visible name when selecting the metric in the UI
	protected $name = "My Metric";

	// Define all submetrics and which charts are available for each submetric
	protected $allowedSubMetrics = [
        'per_user' => ['LineChart','ColumnChart','PieChart'],
    ];

    // Define all filters that can be applied to this metric
    protected $allowedFilters = [
        'username' => [
            'type' => 'text',
            'name' => 'Username'
        ]
    ];

	/**
	 * Implement date filter functionality.
	 * This is needed for all metrics, as the time filter is always available
	 */
    protected function filterFromDate($query, $value)
    {
        return $query->where("created_at" , ">", $value);
    }

    protected function filterUntilDate($query, $value)
    {
        return $query->where("created_at" , "
