public function createGroup(Request $request) { $name = $request->input('name'); $description = $request->input('description'); $password = $request->input('password'); //------------------------ $group = new \App\Group(); $group->name = $name; $group->description = $description; $group->password = $password; $group->user_ids = "[" . auth()->user()->id . "]"; $group->save(); //redirect to the user's home page......... return redirect(url('/home')); }
public function createGroupItem() { $dataArr = ['sorter' => 99, 'show' => true, 'stringfields' => [], 'textfields' => [], 'numbs' => [], 'bools' => [], 'images' => []]; $blockname = $this->name; $groupstruct = config('sitestruct')[$this->name]['group']; $newGroupItem = new \App\Group(); $newGroupItem->block_name = $blockname; $newGroupItem->save(); $dataArr['id'] = $newGroupItem->id; if (array_key_exists('stringfields', $groupstruct)) { foreach ($groupstruct['stringfields'] as $fieldname) { $stringfield = Stringfield::create(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]); $newGroupItem->stringfields()->save($stringfield); $dataArr['stringfields'][$fieldname] = ''; } } if (array_key_exists('textfields', $groupstruct)) { foreach ($groupstruct['textfields'] as $fieldname) { $textfield = Textfield::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]); $newGroupItem->textfields()->save($textfield); $dataArr['textfields'][$fieldname] = ''; } } if (array_key_exists('numbs', $groupstruct)) { foreach ($groupstruct['numbs'] as $fieldname) { $numb = Numb::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]); $newGroupItem->numbs()->save($numb); $dataArr['numbs'][$fieldname] = ''; } } if (array_key_exists('bools', $groupstruct)) { foreach ($groupstruct['bools'] as $fieldname) { $boolitem = Bool::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]); $newGroupItem->bools()->save($boolitem); $dataArr['bools'][$fieldname] = ''; } } if (array_key_exists('images', $groupstruct)) { foreach ($groupstruct['images'] as $fieldname) { $image = Imageitem::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]); $newGroupItem->images()->save($image); $dataArr['images'][$fieldname] = ['alt' => '', 'primary_link' => '', 'secondary_link' => '', 'icon_link' => '', 'preview_link' => '']; } } $newGroupItem->save(); return $dataArr; }