How to create a Dimmer
When we take Voyager for the first time, we see nice panels with different information about dummy data if we typed’em before when we integrate voyager in our laravel project.
Ok, these nice panels are the dimmers. But sometimes we need to modify these panels or add a new panel to adapt our necessities.
In this little guide, I explain how you can create a new dimmer if you need to add more information to your admin panel.
To create a dimmer, we go to app\dimers
and create a new php Class file with a custom name, for example:
CustomDimmer
The class must extend from BaseDimmer
. Now we go to config folder and open voyager.php
and we add the class of our dimmer in widget
section:
App\Dimmers\CustomDimmer::class,
How is the basic structure of a dimmer?
This is the basic configuration of a dimmer, but few times you’ll have modified any element from here, beyond the image, the name or the link.
/***
* * The configuration array.*
* **
* * @var array*
* */
protected $config = [];/***
* * Treat this method as a controller action.*
* * Return view() or other content to display.*
* */
public function run()
{
$count = Voyager::model();
$string = trans_choice('voyager.dimmer.<name>', $count); return view('dimmers.basic', array_merge($this->config, [
'icon' => 'voyager-group',
'title' => "{$count} {$string}",
'button' => [
'text' => __('voyager.dimmer.company_link_text'),
'link' => route('voyager.<name>.index'),
],
'image' => voyager_asset('images/widget-backgrounds/01.jpg'),
]));
}