Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Arrilot's avatar

Widgets for Laravel

For those of you who find using View Composer in some situations not readable enought I've build a small and nice (in my opinion) package providing widget functionality.

https://github.com/arrilot/laravel-widgets

UPD. Added lots of cool staff, feel free to try

0 likes
23 replies
christopher's avatar

thanks for the package.

one thing what i dont really understand is how to bind a variable to the widget ? Or is the way i write this only ( for example ):

public function run()
    {
       $news = News::get();
        return $news;
    }
Arrilot's avatar

You can also create class properties in your widget class. Next, if you want, they can be set/overriden by the config array when the widget is called. Example can be found in the end of github readme.

AndrewPrentis's avatar

I think I must be missing something very obvious but I'm trying to use your package and I can't get it to be recognized in a view - have you got an example to show how to use a widget in a view?

RemiC's avatar

@AndrewPrentis : just call the facade from the view, it's in the docs :

{!! Widget::recentNews() !!}

Will call the RecentNews widget class.

Nice package BTW ! I really like this approach and the witty use of Laravel's Facades.

RemiC's avatar

@Arrilot : Is it possible to have Widgets in several different namespaces ?

AndrewPrentis's avatar

That doesn't work for me - the view just prints {!! Widget::recentNews() !!} to the web page, so I have obviously missed something somewhere...

Arrilot's avatar

@RemiC Yes, but you have to manually add each widget that is not from the default namespace to the package config.

@AndrewPrentis if you happen to use L4 use old blade syntax {{ }}

gnabin01's avatar

how do i call this widget from WYSIWYG editor???

nitish1729's avatar

Great package. However I am running in an issue here. I can't seem to use the widgets with VueJS. As vue doesn't allows script tags in the app. Is there any workaround this?

Amaro's avatar

Great Package! Having fun using it! Running into a problem, when I deploy to server, it does not found the "classes" that widget create! What am I doing wrong?

/vendor/arrilot/laravel-widgets/src/Factories/AbstractWidgetFactory.php

    if (!class_exists($widgetClass)) {
        throw new InvalidWidgetClassException('Class "'.$widgetClass.'" does not exist');
    }
fabuy's avatar

Hi @amaro do you tried composer dump-autoload -o after deployment?

Greatwolf3's avatar

Very interesting package, but I can't get the asynchronous call to the recentNews page to work, could you provide me with a working example?

Thanks and good job

Bensalem-Tn's avatar

i am working with this package , how can i reload widget async widgets by js or jquey

function updateDashboard() { let widgets = @json($widgets) ; const formData = { _token: "{{ csrf_token() }}", region: $('#region').val(), year: $('#year').val(), month: $('#month').val(), start_at: start_at, end_at: end_at, team_id:$('#team_id').val() , assigned_to: $('#user_id').val(), // limit: $('#limit').val() ,

               // pinsStatus: $('#pinsStatus').val()



            };



                $('#arrilot-widget-container-1').html('{{@asyncWidget('App\Widgets\PinCountWidget', ['filters'=>$filters,'pinStatuses'=>$pinStatuses,'teams'=>$teams])}}') ;




        } 

Please or to participate in this conversation.