1. Go to this page and download the library: Download brunolobo/widgets library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Widgets;
use Brunolobo\Widgets\AbstractWidget;
class RecentNews extends AbstractWidget
{
/**
* The configuration array.
*
* @var array
*/
protected $config = [];
/**
* Treat this method as a controller action.
* Return view() or other content to display.
*/
public function run()
{
//
return view('widgets.recent_news', [
'config' => $this->config,
]);
}
}
public function placeholder()
{
return 'Carregando...';
}
class RecentNews extends AbstractWidget
{
/**
* The number of seconds before each reload.
*
* @var int|float
*/
public $reloadTimeout = 10;
}
/**
* Async and reloadable widgets are wrapped in container.
* You can customize it by overriding this method.
*
* @return array
*/
public function container()
{
return [
'element' => 'div',
'attributes' => 'style="display:inline" class="brunolobo-widget-container"',
];
}
class RecentNews extends AbstractWidget
{
/**
* The number of minutes before cache expires.
* False means no caching at all.
*
* @var int|float|bool
*/
public $cacheTime = 60;
}
// add several widgets to the 'sidebar' group anywhere you want (even in controller)
Widget::group('sidebar')->position(5)->addWidget('widgetName1', $config1);
Widget::group('sidebar')->position(4)->addAsyncWidget('widgetName2', $config2);
// display them in a view in the correct order
@widgetGroup('sidebar')
// or
{{ Widget::group('sidebar')->display() }}
Widget::group('sidebar')->wrap(function ($content, $index, $total) {
// $total is a total number of widgets in a group.
return "<div class='widget-{$index}'>{$content}</div>";
})->...;
$id1 = Widget::group('sidebar')->addWidget('files');
$id2 = Widget::group('sidebar')->addAsyncWidget('files');
Widget::group('sidebar')->removeById($id1); // Agora só o segundo wodget está no grupo
Widget::group('sidebar')->addWidget('files');
Widget::group('sidebar')->addAsyncWidget('files');
Widget::group('sidebar')->removeByName('files'); // Widget group está vazio
Widget::group('sidebar')->position(42)->addWidget('files');
Widget::group('sidebar')->position(42)->addAsyncWidget('files');
Widget::group('sidebar')->removeByPosition(42); // Widget group está vazio
Widget::group('sidebar')->addWidget('files');
Widget::group('sidebar')->addAsyncWidget('files');
Widget::group('sidebar')->removeAll(); // Widget group está vazio
bash
php artisan make:widget RecentNews
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.