Restore shifts
This commit is contained in:
miroman-afk
2022-01-10 14:42:35 +03:00
parent 0209970fe1
commit cf1e228f26
5 changed files with 81 additions and 3 deletions

29
models/Subscriber.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace App\Component\Models;
use Illuminate\Database\Eloquent\Model;
class Subscriber extends Model {
protected $table = 'subscribers';
public $timestamps = false;
public static function add($event, $callback, $weight = 0) {
list($destination_module, $destination_method) = explode(':', $callback);
list($source_module, $source_method) = explode(':', $event);
$code = strtolower($destination_module . '_' . $destination_method . '_after_' . $source_module . '_' . $source_method);
if (Subscriber::where('code', $code)->count() == 0) {
$subscriber = new Subscriber([
'code' => $code,
'destination_module' => strtolower($destination_module),
'destination_method' => strtolower($destination_method),
'source_module' => strtolower($source_module),
'source_method' => strtolower($source_method),
'weight' => $weight,
]);
$subscriber->save();
}
}
}