public function update($id, $requestData) { $settings = Settings::first(); $companyname = $settings->company; $user = User::findorFail($id); $password = bcrypt($requestData->password); $role = $requestData->roles; $department = $requestData->departments; if ($requestData->hasFile('image_path')) { $settings = Settings::findOrFail(1); $companyname = $settings->company; $file = $requestData->file('image_path'); $destinationPath = public_path() . '\\images\\' . $companyname; $filename = str_random(8) . '_' . $file->getClientOriginalName(); $file->move($destinationPath, $filename); if ($requestData->password == "") { $input = array_replace($requestData->except('password'), ['image_path' => "{$filename}"]); } else { $input = array_replace($requestData->all(), ['image_path' => "{$filename}", 'password' => "{$password}"]); } } else { if ($requestData->password == "") { $input = array_replace($requestData->except('password')); } else { $input = array_replace($requestData->all(), ['password' => "{$password}"]); } } $user->fill($input)->save(); $user->roles()->sync([$role]); $user->department()->sync([$department]); Session::flash('flash_message', 'User successfully updated!'); return $user; }
public function upload(Request $request, $id) { $settings = Settings::findOrFail(1); $companyname = $settings->company; if (!is_dir(public_path() . '/files/' . $companyname)) { mkdir(public_path() . '/files/' . $companyname, 0777, true); } $file = $request->file('file'); $destinationPath = public_path() . '/files/' . $companyname; $filename = str_random(8) . '_' . $file->getClientOriginalName(); $fileOrginal = $file->getClientOriginalName(); $file->move($destinationPath, $filename); $size = $file->getClientSize(); $mbsize = $size / 1048576; $totaltsize = substr($mbsize, 0, 4); if ($totaltsize > 15) { Session::flash('flash_message', 'File Size can not be bigger then 15MB'); return redirect()->back(); } $input = array_replace($request->all(), ['path' => "{$filename}", 'size' => "{$totaltsize}", 'file_display' => "{$fileOrginal}", 'fk_client_id' => $id]); $document = Document::create($input); Session::flash('flash_message', 'File successfully uploaded'); }
public function getSetting() { return Settings::findOrFail(1); }