settings); $parentDirectoryId = Storage::get(self::CONFIG_FILENAME); $directoryId = isset($settings->directoryId) ? $settings->directoryId : null; $edit = false; // check if directory does not exists $exists = Directory::where('name', $request->name) ->where('parent_id', $parentDirectoryId); if ($directoryId) { $edit = true; $exists = $exists->where('id', '!=', $directoryId); } $exists = $exists->exists(); if ($exists) { throw new WidgetExistsException($request->name); } $directory = new Directory; if ($edit) { $directory = Directory::find($directoryId); } // setup some information about directory $directory->user_id = Auth::user()->id; $directory->parent_id = $parentDirectoryId; $directory->name = $request->name; $directory->description = $request->description; $directory->save(); $settings = [ 'directoryId' => $directory->id, 'sliderClass' => isset($request->containerClass) ? $request->containerClass : '', 'code' => $request->code ]; $widget->settings = json_encode($settings); return $widget; } /** * Getter for presenter/renderer of this widget * * @return WidgetRenderer */ public static function getPresenter() { return Presenters\OrbitSlider::class; } /** * Function for installing given widget * * @return mixed */ public static function install() { $directory = Directory::where('name', self::DIRECTORY_NAME) ->first(); if (!count($directory)) { $directory = Directory::create([ 'name' => self::DIRECTORY_NAME, 'hidden' => true ]); } Storage::put(self::CONFIG_FILENAME, $directory->id); } /** * Function for uninstalling widget */ public static function uninstall() { // TODO: Implement uninstall() method. } }