public static function initBlocks() { $sitestruct = config('sitestruct'); foreach ($sitestruct as $blockname => $blockstruct) { $newBlock = static::find($blockname); if (!$newBlock) { $newBlock = new static(); $newBlock->name = $blockname; if (array_key_exists('title', $blockstruct)) { $newBlock->title = $blockstruct['title']; } if (array_key_exists('stringfields', $blockstruct)) { foreach ($blockstruct['stringfields'] as $fieldname) { $stringfield = Stringfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]); } } if (array_key_exists('textfields', $blockstruct)) { foreach ($blockstruct['textfields'] as $fieldname) { $textfield = Textfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]); } } if (array_key_exists('numbs', $blockstruct)) { foreach ($blockstruct['numbs'] as $fieldname) { $numb = Numb::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]); } } if (array_key_exists('bools', $blockstruct)) { foreach ($blockstruct['bools'] as $fieldname) { $boolitem = Bool::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]); } } if (array_key_exists('images', $blockstruct)) { foreach ($blockstruct['images'] as $fieldname) { $image = Imageitem::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]); } } $newBlock->save(); } } return 'OK'; }