xuuto's avatar
Level 2

laravel how to use view composers to build something like widgets

HI, i would like to help me with, how i could accomplish something like widgets of sidebar, that widgets should consist of dynamic and static, i know it is simple to create dynamic by using view composers, by querying db and passing result the page(s), you want.

but what i want is, how i could also list static content, and dynamic content in the sidebar, for example, 5 top most read articles, and a static content, saying, we are hiring a developer,,,,,,

i want to know the most, accurate way that can be accomplished

i think u got my point.

0 likes
4 replies
bobbybouwmann's avatar

Well, you can just use a blade partial with the static content right? It's nothing more than adding some more HTML to the sidebar to display the extra widget.

xuuto's avatar
Level 2

what about if i want, use something like, WYSIWYG Editor, inorder to save that content into db. and set position, by making some relation with dynamic widget queries, like, most read articles, latest 10 articles, trending articles of this week etc,

bobbybouwmann's avatar

Well, you already have your answer then, right? You need a way in your admin panel to create/maintain these widgets and display them in some order. In general, you can just store the order of the widgets in the database and save the content in the database as well. That should work just fine ;)

xuuto's avatar
Level 2

yeah. i have got the idea, and once, i have contacted one of my mentors, who i canot contact now, he told me that he build website using laravel with this following database schema, i think he told me that website was a news web, that had static and dynamic widgets,

and this is the Db SCHEMA he sent me to use, although i cannot figure out how i could but together using blade files..

databases:
menus: id, name, parent[integer=list of menus], type[enum=section, static, article, url]
statics: id, title, image, content
sections: id, title, description 
widgets: id, type[artcles, static, video, gallery], page[section to appear], ordering[smallint], articles[list, optional, video, gallery, code]
articles: id, title, image, content, section_id

and this is how he told me to use blade files, that i want to be explained in detail.

Views:
home.blade.php
page.blade.php  is for sections
widgets.blade.php    this will be included in page.blade and is responsible for Type of widget for that page. 

Suppose, that page has static widget or widget  showing displaying top 5 articles , or a widget displaying latest 5 articles, or widget displaying video. Of course you should make a separate view for each one.

static.blade.
article.blade

that is what he sent me as i translated into english, i think this makes sense, but somehow i think i cannot figure out how exaclty i can include files and how ordering works.

thanks in advance, i really appreciate if you could give me a detailed info how exactly it can be but together to make dynamic widgets.

thanks once more

Please or to participate in this conversation.