protected function saveConfigs() { foreach ($this->configs as $key => $value) { $config = Config::where('key', '=', $key)->first(); if ($config == null) { $config = new Config(); } $config->key = $key; $config->value = $value; $config->save(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(UserCreateFormRequest $request) { if (Auth::check() && $this->rolechucnangs && $this->rolechucnangs->Them == 1) { if ($request->input('doi') == 0) { $doi = NULL; } else { $doi = $request->input('doi'); } $capbac = $request->input('capbac'); if ($capbac == 0) { $capbac = NULL; } $chucvu = $request->input('chucvu'); if ($chucvu == 0) { $chucvu = NULL; } if ($request->input('canhan') == 'on') { $canhan = 1; } else { $canhan = NULL; } $config = new Config(['layout' => '', 'navbar' => '', 'sidebar' => '', 'breadcrumbs' => '', 'compactsidebar' => '']); $config->save(); $config_id = $config->id; $user = new User(array('username' => $request->input('username'), 'name' => $request->input('name'), 'email' => $request->input('email'), 'password' => \Hash::make($request->input('password')), 'role_id' => $request->input('role'), 'doi_id' => $doi, 'phong_id' => $request->input('phong'), 'canhan' => $canhan, 'config_id' => $config_id, 'capbac_id' => $capbac, 'chucvu_id' => $chucvu)); $user->save(); $insertedId = $user->id; //get user insert id $role_id = $request->input('role'); // get role id $userfind = User::find($insertedId); $userfind->assignRole($role_id); return \Redirect::route('user.index')->with('message', 'Lưu thành công!'); } else { return \Redirect::route('user.index')->with('message-error', 'Không có quyền truy cập'); } }