@yatort

Одинаковые конфиги в виджетах, как оптимизировать?

Всем привет!

У меня много-много виджетов, все они используют одинаковые конфиги, либо почти одинаковые, можно ли их как то выносить?

В документации https://github.com/arrilot/laravel-widgets вроде есть информация, но не достаточно понимания как это сделать

из документации

Note 2: You may want (but you probably don't) to create your own BaseWidget and inherit from it. That's fine. The only edge case is merging config defaults from a parent and a child. In this case do the following:

Do not add protected $config = [...] line to a child.

Instead add defaults like this:
public function __construct(array $config = [])
{
    $this->addConfigDefaults([
        'child_key' => 'bar'
    ]);

    parent::__construct($config);
}



мой дублирующийся код:
тьк

class Ac extends AbstractWidget
{
    /**
     * The configuration array.
     *
     * @var array
     */
    
    protected $config = [
        'block_id' => null,
        'site_id' => null,
        'type' => null,
        'view' => null,
        'block_title' => null,
        'block_offer' => null,
        'block_description' => null,
        'image' => null,
        'form' => null,
        'form_id' => null,
        'form_btn_name' => null,
        'folder' => null,
        'pack' => null,
        'item' => null,
        'size' => null,
        'count' => null,
        'back' => null,
        'main' => null,

        'section_id' => null,
        'category_id' => null,
        'item_id' => null,
    ];

    /**
     * Treat this method as a controller action.
     * Return view() or other content to display.
     */
    public function run()
    {
        $site_id = $this->config['site_id'];
        $view = $this->config['view'];
        $type = $this->config['type'];
        $manager_id = $this->config['manager_id'];
        $item = $this->config['item'];

        $count = $this->config['count'];

        $back = $this->config['back'];
        $block_id = $this->config['block_id'];
        $block_title = $this->config['block_title'];
....


Господа на опыте, можете на примере показать как это реализовать?
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы