Пример #1
1
 public function __construct(Request $request)
 {
     $this->currentModel = new Content();
     $this->langModel = new ContentLang();
     $this->validation = \Validator::make($request->all(), ['name' => 'required:structure|max:255']);
     $modelStructure = new Structure();
     $treeStructure = $modelStructure->get()->sortBy('position');
     foreach ($treeStructure as $key => $struct) {
         $lang = StructureLang::where(['structure_id' => $struct['id'], 'language_id' => FormLang::getCurrentLang()])->first();
         if ($lang) {
             $treeStructure[$key]->name = $lang->name;
             $treeStructure[$key]->link = action('\\Application\\Admin\\Http\\Controllers\\StructureController@getEdit', ['id' => $struct['id']]);
         } else {
             unset($treeStructure[$key]);
         }
     }
     $treeStructure->linkNodes();
     $str = $treeStructure->toArray();
     $witgetStructureTree = new TreeBuilder();
     $TreeStructure = $witgetStructureTree->view($str, '<ul>{val}</ul>', '<li data-href="/admin/content/structure/{id}">{name}</li>', '<li data-href="/admin/content/structure/{id}" class="folder expanded">{name}<ul>{|}</ul></li>');
     view()->share('StructureTree', $TreeStructure);
     view()->share('id_structure', $request->route('id_structure'));
     $this->itemName = 'Content';
     $this->template = 'content';
     $this->layout = 'dual_sidebars';
     parent::__construct();
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function postStore(Request $request)
 {
     $this->validation->mergeRules('alias', ['required', 'regex:/^[a-zа-я\\d-]+$/', 'unique:structure', 'max:255']);
     if ($this->validation->fails()) {
         return $this->validation->errors()->toJson();
     }
     $structure = new Structure();
     $data = $request->all();
     $position = $this->currentModel->where('parent_id', null)->max('position');
     $structure->alias = $data['alias'];
     $structure->parent_id = $data['parent_id'];
     $structure->controller = $data['controller'];
     $structure->position = ++$position;
     $structure->save();
     $structure->structureLang()->create(['name' => $data['name'], 'language_id' => $data['language_id'], 'description' => $data['description']]);
     return Main::redirect(Route('edit_structure', ['id' => $structure->id]), '302', 'Structure was saved', 'Saved', 'success');
 }