PHP code example of rinvex / laravel-widgets

1. Go to this page and download the library: Download rinvex/laravel-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/ */

    

rinvex / laravel-widgets example snippets




namespace App\Widgets;

use Rinvex\Widgets\Models\AbstractWidget;

class RecentPosts extends AbstractWidget
{
    /**
     * Treat this method as a normal PHP method, or a controller action.
     * You may return view() or other content to render and display.
     */
    public function make()
    {
        //
    }
}

$recentPosts = app('rinvex.widgets')->make('App\Widgets\RecentPosts');

$recentPosts = Widget::make('App\Widgets\RecentPosts', ['param1' => 'Value #1'], true);

public function placeholder()
{
    return 'Loading...';
}

class RecentPosts extends AbstractWidget
{
    /**
     * The number of seconds before each reload.
     *
     * @var float
     */
    protected $reloadTimeout;
}

class RecentPosts extends AbstractWidget
{
    /**
     * The widget container template.
     *
     * @var string
     */
    protected $container = 'rinvex/widgets::container';
}

// add several widgets to the 'sidebar' group
Widget::group('sidebar')->addWidget(Widget::make('App\Widgets\RecentPosts'), 10);
Widget::group('sidebar')->addWidget(Widget::make('App\Widgets\LatestVisitors'), 20);

$sidebar = Widget::group('sidebar')->render();

$groups = Widget::groups();

Widget::group('sidebar')->separateWith('<hr>');

Widget::group('sidebar')->wrapCallback(function ($key, $widget) {
    return "<div class='widget-{$key}'>{$widget}</div>";
});

// Check if widget group is empty or not
Widget::group('sidebar')->isEmpty(); // bool

// Get widgets count in the widget group
Widget::group('sidebar')->count(); // int

// Check if there's any widget groups or not
Widget::groups()->isEmpty(); // bool

// Get widget groups count
Widget::groups()->count(); // int
ssh
php artisan make:widget RecentPosts