/** * Build our views files */ public function build() { $cache = new QuickCache(); $cached = $cache->get('fieldsinfo'); $this->template = [0 => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'view_index', 1 => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'view_edit', 2 => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'view_create']; $this->name = $cached['name']; $this->fields = $cached['fields']; $this->files = $cached['files']; $this->names(); $template = (array) $this->loadTemplate(); $template = $this->buildParts($template); $this->publish($template); }
/** * Build our request file */ public function build() { $cache = new QuickCache(); $cached = $cache->get('fieldsinfo'); $this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'request'; $this->name = $cached['name']; $this->fields = $cached['fields']; $this->soft = $cached['soft_delete']; $this->names(); $template = [$this->loadTemplate(), $this->loadTemplate()]; $template = $this->buildParts($template); $this->publish($template); }
/** * Build our controller file */ public function build() { $cache = new QuickCache(); $cached = $cache->get('fieldsinfo'); $this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'controller'; $this->name = $cached['name']; $this->fields = $cached['fields']; $this->relationships = $cached['relationships']; $this->files = $cached['files']; $this->names(); $template = (string) $this->loadTemplate(); $template = $this->buildParts($template); $this->publish($template); }
/** * Build our model file */ public function build() { $cache = new QuickCache(); $cached = $cache->get('fieldsinfo'); $this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'model'; $this->name = $cached['name']; $this->fields = $cached['fields']; $this->soft = $cached['soft_delete']; $this->password = $cached['password']; $this->date = $cached['date']; $this->names(); $template = (string) $this->loadTemplate(); $template = $this->buildParts($template); $this->publish($template); }
/** * Insert new crud * * @param Request $request * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function insert(Request $request) { $validation = Validator::make($request->all(), ['name' => 'required', 'title' => 'required', 'soft' => 'required']); if ($validation->fails()) { return redirect()->back()->withInput()->withErrors($validation); } // Get model names $cruds = Crud::all(); $models = []; foreach ($cruds as $crud) { $tableName = strtolower($crud->name); $models[$crud->id] = $tableName; } // Init QuickCache $cache = new QuickCache(); $cached = []; $cached['relationships'] = 0; $cached['files'] = 0; $cached['password'] = 0; $cached['date'] = 0; $fields = []; foreach ($request->f_type as $index => $field) { $fields[$index] = ['type' => $field, 'title' => $request->f_title[$index], 'label' => $request->f_label[$index], 'validation' => $request->f_validation[$index], 'value' => $request->f_value[$index], 'default' => $request->f_default[$index], 'relationship_id' => $request->has('f_relationship.' . $index) ? $request->f_relationship[$index] : '', 'relationship_name' => $request->has('f_relationship.' . $index) ? $models[$request->f_relationship[$index]] : '', 'relationship_field' => $request->has('f_relationship_field.' . $request->f_relationship[$index]) ? $request->f_relationship_field[$request->f_relationship[$index]] : '', 'texteditor' => $request->f_texteditor[$index], 'size' => $request->f_size[$index] * 1024, 'show' => $request->f_show[$index]]; if ($field == 'relationship') { $cached['relationships']++; } elseif ($field == 'file') { $cached['files']++; } elseif ($field == 'password') { $cached['password']++; } elseif ($field == 'date') { $cached['date']++; } } $cached['fields'] = $fields; $cached['name'] = $request->name; $cached['soft_delete'] = $request->soft; $cache->put('fieldsinfo', $cached); // Create crud entry Crud::create(['position' => 0, 'icon' => $request->icon != '' ? $request->icon : 'fa-database', 'name' => $request->name, 'title' => $request->title, 'parent_id' => null, 'roles' => '1']); // Create migrations $migrationBuilder = new MigrationBuilder(); $migrationBuilder->build(); // Create model $modelBuilder = new ModelBuilder(); $modelBuilder->build(); // Create request $requestBuilder = new RequestBuilder(); $requestBuilder->build(); // Create controller $controllerBuilder = new ControllerBuilder(); $controllerBuilder->build(); // Create views $viewsBuilder = new ViewsBuilder(); $viewsBuilder->build(); // Call migrations Artisan::call('migrate'); // Destroy our cache file $cache->destroy('fieldsinfo'); return redirect(config('quickadmin.route')); }
/** * Insert new menu * * @param Request $request * * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function insertCrud(Request $request) { $validation = Validator::make($request->all(), ['name' => 'required|unique:menus,name', 'title' => 'required', 'soft' => 'required']); if ($validation->fails()) { return redirect()->back()->withInput()->withErrors($validation); } // Get model names $menus = Menu::all(); $models = []; foreach ($menus as $menu) { $tableName = strtolower($menu->name); $models[$menu->id] = $tableName; } // Init QuickCache $cache = new QuickCache(); $cached = []; $cached['relationships'] = 0; $cached['files'] = 0; $cached['password'] = 0; $cached['date'] = 0; $cached['datetime'] = 0; $cached['enum'] = 0; $fields = []; foreach ($request->f_type as $index => $field) { $fields[$index] = ['type' => $field, 'title' => $request->f_title[$index], 'label' => $request->f_label[$index], 'helper' => $request->f_helper[$index], 'validation' => $request->f_validation[$index], 'value' => $request->f_value[$index], 'default' => $request->f_default[$index], 'relationship_id' => $request->has('f_relationship.' . $index) ? $request->f_relationship[$index] : '', 'relationship_name' => $request->has('f_relationship.' . $index) ? $models[$request->f_relationship[$index]] : '', 'relationship_field' => $request->has('f_relationship_field.' . $request->f_relationship[$index]) ? $request->f_relationship_field[$request->f_relationship[$index]] : '', 'texteditor' => $request->f_texteditor[$index], 'size' => $request->f_size[$index] * 1024, 'show' => $request->f_show[$index], 'dimension_h' => $request->f_dimension_h[$index], 'dimension_w' => $request->f_dimension_w[$index], 'enum' => $request->f_enum[$index]]; if ($field == 'relationship') { $cached['relationships']++; } elseif ($field == 'file' || $field == 'photo') { $cached['files']++; } elseif ($field == 'password') { $cached['password']++; } elseif ($field == 'date') { $cached['date']++; } elseif ($field == 'datetime') { $cached['datetime']++; } elseif ($field == 'enum') { $cached['enum']++; } } // dd($fields); $cached['fields'] = $fields; $cached['name'] = $request->name; $cached['soft_delete'] = $request->soft; $cache->put('fieldsinfo', $cached); $roles = Role::all(); $rolesInsert = ''; $first = true; foreach ($roles as $role) { if ($request->{'role-' . $role->id} == 1) { if ($first != true) { $rolesInsert .= ','; } $rolesInsert .= $role->id; $first = false; } } // Create menu entry Menu::create(['position' => 0, 'icon' => $request->icon != '' ? $request->icon : 'fa-database', 'name' => $request->name, 'title' => $request->title, 'parent_id' => $request->parent_id != 0 ? $request->parent_id : null, 'roles' => $rolesInsert]); // Create migrations $migrationBuilder = new MigrationBuilder(); $migrationBuilder->build(); // Create model $modelBuilder = new ModelBuilder(); $modelBuilder->build(); // Create request $requestBuilder = new RequestBuilder(); $requestBuilder->build(); // Create controller $controllerBuilder = new ControllerBuilder(); $controllerBuilder->build(); // Create views $viewsBuilder = new ViewsBuilder(); $viewsBuilder->build(); // Call migrations Artisan::call('migrate'); // Destroy our cache file $cache->destroy('fieldsinfo'); return redirect(config('quickadmin.route')); }