afterReorder
Is it possible to add a function before or after saving the positions of my module?
I need it in order to clear the cache of my site every time the position of the elements changes.
I need something similar to this
<?php
namespace A17\Twill\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
use A17\Twill\Models\Model;
class ReorderNestedModuleItems implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
protected $modelClass;
protected $ids;
public function __construct(Model $model, array $ids)
{
$this->modelClass = get_class($model);
$this->ids = $ids;
}
public function handle()
{
DB::transaction(function () {
// Here custom function app($this->modelClass)->saveTreeFromIds($this->ids); }, 3); } }
// Here custom function app($this->modelClass)->saveTreeFromIds($this->ids); }, 3); } }
5 Replies
Hi @luciano.mizra a module with HasPosition but not nested, correct?
An event is fired here https://github.com/area17/twill/blob/35d0bbcb8a35e04bd3c52de4b82c54bd095d977f/src/Http/Controllers/Admin/ModuleController.php#L1664
GitHub
twill/src/Http/Controllers/Admin/ModuleController.php at 35d0bbcb8a...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
So you can listen to
cms-module.saved
Great, so I just need to place the "fireEvent" function in my controller.
It's already fired when you reorder