/**
  * Load Modules List From Database
  */
 public function loadModulesFromDatabase()
 {
     //	Reset List
     $this->modules = array();
     //	Modules List
     $items = ModuleItem::orderBy("order_index", "ASC")->get();
     //	Process List
     foreach ($items as $item) {
         //  Check if the Path of Module is Valid
         if ($this->app["files"]->exists($item->path)) {
             //	Create Instance
             $module = LaravelModule::createInstance($this->app, $item);
             //  Checkif Module is Fine
             if ($module->isFine()) {
                 //  Store Instance
                 $this->modules[$item->module] = $module;
             }
         }
     }
     //	Sort Modules List
     uasort($this->modules, array($this, 'sort_modules'));
 }
 /**
  * Sync Details to Database
  */
 public function syncToDatabase($force = false)
 {
     //	Get Info From Database
     $this->moduleItem = ModuleItem::findModule($this->name);
     //	Check if Exists
     if ($this->moduleItem) {
         //	Check Version Installed
         if ($force || !ModuleVersionItem::versionInstalled($this->name, $this->version)) {
             //	Update Data
             $this->moduleItem->version = $this->version;
             $this->moduleItem->name = $this->moduleName;
             $this->moduleItem->description = $this->moduleDescription;
             $this->moduleItem->depends_on = serialize($this->dependsOn);
             $this->moduleItem->meta_data = serialize($this->metaData);
             $this->moduleItem->order_index = $this->order;
             $this->moduleItem->locked = $this->locked;
             $this->moduleItem->save();
             //	Run the Installation Hook
             $this->runHook("updated");
         }
         //	Store Details from Database
         $this->loadFromDatabaseObject($this->moduleItem);
     } else {
         //	Check for Auto Order Index
         if ($this->order == "auto") {
             //	Get Last Item
             $last_item = ModuleItem::orderBy("order_index", "DESC")->limit(1)->get()->first();
             //	Set New Order
             $this->order = $last_item ? $last_item->order_index + 1 : 0;
         }
         //	Insert New Data
         $this->moduleItem = new ModuleItem();
         $this->moduleItem->module = $this->name;
         $this->moduleItem->version = $this->version;
         $this->moduleItem->name = $this->moduleName;
         $this->moduleItem->description = $this->moduleDescription;
         $this->moduleItem->path = $this->modulePath;
         $this->moduleItem->depends_on = serialize($this->dependsOn);
         $this->moduleItem->meta_data = serialize($this->metaData);
         $this->moduleItem->is_package = $this->is_package;
         $this->moduleItem->order_index = $this->order;
         $this->moduleItem->locked = $this->locked;
         $this->moduleItem->save();
         //	Save Version Installed Informations
         ModuleVersionItem::versionInstalled($this->name, $this->version);
         //	Run the Installation Hook
         $this->runHook("installed");
     }
     //  Set Registered In System
     $this->from_db = true;
 }
 public function index()
 {
     setPageData("items", ModuleItem::orderBy("order_index", "ASC")->paginate(10));
     return $this->_render();
 }