FEATURE: use module_settings field instaed of config().
This way should be more reliable, because config() is available only after publishing module, however I can't publish module when it does not have config (module.json). In this way I can select all modules from database and generate module.json for each of them.
This commit is contained in:
+38
-5
@@ -3,23 +3,56 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
/**
|
||||
* Class Module
|
||||
*/
|
||||
class Module extends Model
|
||||
{
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'handler',
|
||||
'name',
|
||||
'description',
|
||||
'alias'
|
||||
'alias',
|
||||
'module_settings',
|
||||
'enabled'
|
||||
];
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* Create new module in database
|
||||
*
|
||||
* @param $name
|
||||
* @param $alias
|
||||
* @param string $description
|
||||
* @param null $handler
|
||||
* @param array $settings
|
||||
*
|
||||
* @return Module
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
public static function install($name, $alias, $description, $handler, $settings)
|
||||
{
|
||||
// check if user does not want to install module in runtime
|
||||
if (!App::runningInConsole()) {
|
||||
throw new \ErrorException('Modules can be installed only via Artisan!');
|
||||
}
|
||||
|
||||
// insert module into database
|
||||
$module = Module::create([
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'handler' => $handler,
|
||||
'alias' => $alias,
|
||||
'module_settings' => json_encode($settings),
|
||||
'enabled' => 1
|
||||
]);
|
||||
|
||||
// install something module-specific
|
||||
call_user_func([$handler, 'install']);
|
||||
|
||||
return $module;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user