diff --git a/include/eloquent.php b/include/eloquent.php index 0bc89154..05a5342c 100644 --- a/include/eloquent.php +++ b/include/eloquent.php @@ -1,17 +1,10 @@ addConnection($connectionMysql, $connectionName); -$capsule->setAsGlobal(); -$capsule->bootEloquent(); -$capsule->getConnection($connectionName)->enableQueryLog(); +\Nexus\Database\DB::bootEloquent($connectionMysql); diff --git a/nexus/Database/DB.php b/nexus/Database/DB.php index d4802c1b..3a9f64ab 100644 --- a/nexus/Database/DB.php +++ b/nexus/Database/DB.php @@ -2,6 +2,8 @@ namespace Nexus\Database; +use Illuminate\Database\Capsule\Manager as Capsule; + class DB { private $driver; @@ -209,4 +211,19 @@ class DB return $result; } + public static function bootEloquent(array $config) + { + $capsule = new Capsule; + $connectionName = self::ELOQUENT_CONNECTION_NAME; + $capsule->addConnection($config, $connectionName); + $capsule->setAsGlobal(); + $capsule->bootEloquent(); + $capsule->getConnection($connectionName)->enableQueryLog(); + } + + public static function schema(): \Illuminate\Database\Schema\Builder + { + return Capsule::schema(self::ELOQUENT_CONNECTION_NAME); + } + } diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index a5f6fb18..98ff1b23 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -2,6 +2,8 @@ namespace Nexus\Install; +use App\Models\Category; +use App\Models\Icon; use Nexus\Database\DB; class Update extends Install @@ -62,6 +64,12 @@ class Update extends Install $id = DB::insert($table, $insert); $this->doLog("[ADD CUSTOM FIELD MENU] insert: " . json_encode($insert) . " to table: $table, id: $id"); } + if (WITH_LARAVEL && DB::schema()->hasColumn('categories', 'icon_id')) { + $icon = Icon::query()->orderBy('id', 'asc')->first(); + if ($icon) { + Category::query()->where('icon_id', 0)->update(['icon_id' => $icon->id]); + } + } } } diff --git a/nexus/Install/install/install.php b/nexus/Install/install/install.php index ef033d47..c4f7ef1e 100644 --- a/nexus/Install/install/install.php +++ b/nexus/Install/install/install.php @@ -214,7 +214,7 @@ if ($currentStep == 5) {