Files
core/app/Models/Module.php
T
Michal Kváček 6d13576185 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.
2016-03-14 13:14:01 +01:00

58 lines
1.6 KiB
PHP

<?php
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',
'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;
}
}