Download the PHP package imanghafoori/laravel-widgetize without Composer

On this page you can find all versions of the php package imanghafoori/laravel-widgetize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-widgetize

Laravel Widgetize

widgetize_header

[![Maintainability](https://api.codeclimate.com/v1/badges/265609ba555d5fd06560/maintainability)](https://codeclimate.com/github/imanghafoori1/laravel-widgetize/maintainability) Quality Score [![Latest Stable Version](https://poser.pugx.org/imanghafoori/laravel-widgetize/v/stable)](https://packagist.org/packages/imanghafoori/laravel-widgetize) [![Awesome Laravel](https://img.shields.io/badge/Awesome-Laravel-brightgreen.svg)](https://github.com/chiraggude/awesome-laravel) [![Monthly Downloads](https://poser.pugx.org/imanghafoori/laravel-widgetize/d/monthly)](https://packagist.org/packages/imanghafoori/laravel-widgetize/stats) [![Code Coverage](https://scrutinizer-ci.com/g/imanghafoori1/laravel-widgetize/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/imanghafoori1/laravel-widgetize/?branch=master) [![tests](https://github.com/imanghafoori1/laravel-widgetize/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/imanghafoori1/laravel-widgetize/actions/workflows/tests.yml) [![Imports](https://github.com/imanghafoori1/laravel-widgetize/actions/workflows/imports.yml/badge.svg?branch=master)](https://github.com/imanghafoori1/laravel-widgetize/actions/workflows/imports.yml)

:ribbon::ribbon: "_cleaner code_" :heavy_plus_sign: "_easy caching_" :ribbon::ribbon:

Built with :heart: for every smart laravel developer


More readings:

This page may look long and boring to read at first, but bear with me!!!

I bet if you read through it you won't get disappointed at the end.So let's Go... :horse_racing:


Installation: :arrow_down:

:electric_plug: (For Laravel <=5.4) Next, you must add the service provider to config/app.php :electric_plug:

Publish your config file

:fire: And you will be on fire!:fire:

A lot of docs are included in the generated widget file so it is not needed to memorize or even read the rest of this page. You can jump right-in and start using it.

Overview:

This package helps you in:


When to use this package?

This concept (this design pattern) really shines when you want to create tall web pages with multiple sections (on sidebar, menu, carousels ...) and each widget needs separate sql queries and php logic to be provided with data for its template. Anyway installing it has minimal overhead since surprisingly it is just a small abstract class and Of course you can use it to refactor your monster code and tame it into managable pieces or boost the performance 4x-5x times faster! :dizzy:


What is a widget?

You can think of a widget as a blade partial (which know how to provide data for itself.)

You can include @widget('myWidget') within your blade files and it will turn into HTML!!!

So you can replace @include('myPartial') with @widget('myWidget') in our laravel applications.


:gem: Technical Features:

:small_blue_diamond: 1. It optionally caches the output of each widget. (which give a very powerful, flexible and easy to use caching opportunity) You can set different cache config for each part of the page. Similar to ESI standard.

:small_blue_diamond: 2. It optionally minifies the output of the widget.

:small_blue_diamond: 3. It shows debug info for your widgets as html title="" attributes.

:small_blue_diamond: 4. php artisan make:widget command

:small_blue_diamond: 5. It helps you to have a dedicated presenter class of each widget to clean up your views.

:small_blue_diamond: 6. It extends the Route facade with Route::jsonWidget , Route::widget


What happens when your write @widget('SomeWidget') in your views

Given that we have disabled caching in the widgetize config file...

1 - It first looks for "SomeWidget" class to get config from.

2 - Then calls the widget's controller method and gets some data from it.

3 - Using that data it "compiles" (in other word "renders") the blade file ($template). (to produce some html)

4 - (If caching is enabled for the widget) it puts a copy of the resulting html in cache, for future use.

5 - At last, it returns the final HTML. (or maybe json)


"Widgets" vs. "View Composers":

You might think that "view composers" are already doing the job, so why "widgets" ?

1- The worst thing about view composers is you never know which composer is attached to a @include not to mention other members of your team.

2- You have no way of passing data to the compose() method from your view. They receive a \Illuminate\View\View object. so they can not be re-used to expose json data. widgetize designed to provide fully freedom and resuability for widget-controllers.

3- They offer no caching out of the box.


:bulb: Sample Code:

How to generate a widget?

You can use : php artisan make:widget MyWidget to make your widget class.

Sample widget class :

App\Widgets\MyWidgetView.blade.php :

Ok, Now it's done! We have a ready to use widget. let's use it...

Then how to use that widget?

In a normal day to day view (middle-end):


An other way to think of @widget() in your blade files :


What is the slot?

Slots help you position your HTML or blade code in a widget, and allow the parent widget to arrange it, and improves your widget reusability.

How to define a slot?

To use the slot, you should use instead of and close the directive , Then define your slot middle of it. Look at the syntax:

also, you can pass your data:

How to use the slot?

App\Widgets\MyWidgetView.blade.php :


:book: Documentation:

:earth_africa: Global Config:

You can set the variables in "config/widgetize.php" file to globally set some configs for you widgets and override them per widget if needed. Read the docblocks in config/widgetize.php file for more info.

:blue_car: Per Widget Config:

public $template (string)

If you do not set it,By default, it refers to app/Widgets folder and looks for the 'widgetNameView.blade.php' (Meaning that if your widget is app/Widgets/home/recentProducts.php the default view for that is app/Widgets/home/recentProductsView.blade.php) Anyway you can override it to point to any partial in views folder.(For example: public $template='home.footer' will look for resource/views/home/footer.blade.php) So the entire widget lives in one folder:

| app\Widgets\Homepage\RecentProductsWidget.php

| app\Widgets\Homepage\RecentProductsWidgetView.blade.php

public $controller (string)

If you do not want to put your data method on your widget class, you can set public $controller = App\Some\Class\MyController::class and put your public data method on a dedicated class.(instead od having it on your widget class)

or you may also refrence it like this :

public $controller = [\App\Some\Class\MyRepo::class, 'myMethod'];

public $controller = '\App\Some\Class\MyRepo@myMethod';

public $presenter (string)

If you do not want to put your present method on your widget class, you can set public $presenter = App\Some\Class\MyPresenter::class and put your public present method on a dedicated class.The data returned from your controller is first piped to your presenter and then to your view.(So if you specify a presenter your view file gets its data from the presenter and not the controller.)

public $cacheLifeTime (int)

If you want to override the global cache life time (which is set in your config file).

value effect
-1 forever
'forever' forever
0 disable
1 1 minute

public $cacheTags (array)

You can set tags public $cacheTags = ['tag1','tag2'] to target a group of widgets and flush their cache. using the helper function :

This causes all the widgets with 'someTag' or 'tag1' to be refreshed.

Note: Tagging feature works with ALL the laravel cache drivers including 'file' and 'database'.

public $cacheView

In case you want your view to be real-time but your controller results to be cached, set this to false. defalut value is true.

public function cacheKey

If you want to explicitly define the cache key used to store the html result of your widget, you can implement this method.

public function extraCacheKeyDependency

It is important to note that if your final widget HTML output depends on PHP's super global variables and you want to cache it,Then they must be included in the cache key of the widget.

You may want to look at the source code and read the comments for more information.

Tip: If you decide to use some other template engine instead of Blade it would be no problem.

:book: Solid Design Pattern

You can Find more information in the article below : It is a 3 minutes read.

Single Responsibility Prinsiple


Q&A

Q&A:How to expose only a widget HTML content from a url ?

A GET request to /some-url/{a}/{b} will see the widget. a and b parameters are passed to widget controller.

jsonWidget will expose the cached data returned from the widget's controller.


Q&A:How to reference widget controllers from routes ?

This way you can also expose your data as json for client-side apps.

* It is important to put \ before App when you want to refer to a class outside the Http\Controller folder.


:raising_hand: Contributing

If you find an issue, or have a better way to do something, feel free to open an issue or a pull request. If you use laravel-widgetize in your open source project, create a pull request to provide it's url as a sample application in the README.md file.

:exclamation: Security

If you discover any security related issues, please use the security tab instead of using the issue tracker.

:star: Your Stars Make Us Do More :star:

As always if you found this package useful and you want to encourage us to maintain and work on it. Just press the star button to declare your willing.

Star History

Star History Chart

More from the author:

Laravel Microscope

:gem: It automatically find bugs in your laravel app


Laravel middlewarize

:gem: You can put middleware on any method calls.


Laravel HeyMan

:gem: It allows to write expressive code to authorize, validate and authenticate.


Laravel Terminator

:gem: A minimal yet powerful package to give you opportunity to refactor your controllers.


Laravel AnyPass

:gem: It allows you login with any password in local environment only.


Great spirits have always encountered violent opposition from mediocre minds. "Albert Einstein"


All versions of laravel-widgetize with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3|7.2.*|7.3.*|7.4.*|^8.0
laravel/framework Version ~5.1|6.*|7.*|8.*|9.*|10.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package imanghafoori/laravel-widgetize contains the following files

Loading the files please wait ....