UniSharp / laravel-widgetify by g0110280

help dealing with data in partial view with laravel.
11
1
6
Package Data
Maintainer Username: g0110280
Maintainer Contact: service@unisharp.com (Unisharp Ltd.)
Package Create Date: 2015-10-30
Package Last Update: 2015-11-10
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:07:17
Package Statistics
Total Downloads: 11
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 6
Total Forks: 0
Total Open Issues: 0

Widget generator for Laravel

  • Help you get partial views as widgets

Installation

  1. install package

        composer require unisharp/laravel-widgetify
    
  2. edit config/app.php

    service provider :

        Unisharp\Widget\WidgetServiceProvider::class,
    

    class aliases :

        'Widget' => Unisharp\Widget\WidgetFacade::class,
    
  3. publish widget template class

        php artisan vendor:publish --tag=widget_example
    

Usage

    Widget::set('side', 'widget-class-name', $args = []]);
    // set widgets with position

    Widget::get('side');
    // get all widgets of a position

Example

  1. in App\Widgets\Block.php :

        class Block implements WidgetInterface
        {
            public $view = 'home.widgets.side_html';
    
            public function getData($args)
            {
                return ['html' => \App\Utility::getPageByAlias($args['alias'])];
            }
        }
    
  2. in home.widgets.side_html.blade.php :

        @if(!empty($html->content))
            <section class="facebook-plugin">
                {!! $html->content !!}
            </section>
        @endif
    
  3. set widgets in in controller :

        \Widget::set('side', 'block', ['alias' => 'side_top_html']);
        \Widget::set('side', 'facebook');
        \Widget::set('side', 'block', ['alias' => 'side_mid_html']);
        \Widget::set('side', 'subscription');
        \Widget::set('side', 'block', ['alias' => 'side_buttom_html']);
    
  4. display widgets in view :

        {!! \Widget::get('side') !!}