/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store() { $request = Request::all(); // $this->validate($request); \App\Document::create($request); return redirect('document'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['company' => 'required', 'owner' => 'required']); $input = $request->all(); Document::create($input); Session::flash('flash_message', 'Document successfully added!'); return redirect()->back(); }
protected function postDocument(Request $request) { if ($request->exists('file') && $request->exists('name')) { $user = Auth::user(); $user_id = $user->id; $file = $request->file('file'); $randomFolder = str_random(12); $fileName = $file->getClientOriginalName(); $file->move(base_path() . '/public/file/' . $randomFolder . '/', $file->getClientOriginalName()); Document::create(['name' => $request->name, 'description' => $request->description, 'status' => 'pre-request', 'officer_id' => $user->id, 'filename' => $fileName, 'file_folder' => $randomFolder]); return Redirect::route('documents')->with('success', 'Document added successful'); } else { return Redirect::route('documents')->with('fail', 'Something wrong!!'); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // check that the file is valid if ($request->hasFile('original_file') && (!$request->file('original_file')->isValid() || $request->file('original_file')->getClientMimeType() !== 'text/xml')) { throw new Exception('Please upload a valid xml document.'); } if ($request->hasFile('original_file')) { return $this->storeFile($request); } if (!($file_original_name = Session::get('file_original_name'))) { throw new Exception('Please upload a valid xml document.'); } //create the document record $input = Input::all(); $input['raw_file_path'] = 'placeholder'; $input['parsed_file_path'] = 'placeholder'; $document = Document::create($input); if (!empty($input['tags'][0])) { Tag::resolveTags($document, explode(',', $input['tags'][0])); } // get the file $file_temp_name = Session::get('file_temp_name'); $file_temp_path = ".." . DIRECTORY_SEPARATOR . "temp"; $file_temp = $file_temp_path . DIRECTORY_SEPARATOR . $file_temp_name; $file_new_name = "{$document->id}_{$file_original_name}_raw.xml"; $file_new_name_p = "{$document->id}_{$file_original_name}_parsed.pdf"; $file_new_path = ".." . DIRECTORY_SEPARATOR . "documents"; $file_new = $file_new_path . DIRECTORY_SEPARATOR . $file_new_name; Storage::move($file_temp, $file_new); // update the document $document->update(['raw_file_path' => $file_new_name, 'parsed_file_path' => $file_new_name_p]); Event::fire(new DocumentWasUploaded($document)); Session::pull('file_original_name'); Session::pull('file_temp_name'); Session::pull('file_temp_path'); return $this->operationSuccessful(); }
/** * Update the specified resource in storage. * * @param Inscription $inscription * @return Response */ public function update(Inscription $inscription, Request $request) { $this->authorize('edit', $inscription); //$this->validate($request, ['name' => 'required']); // Uncomment and modify if you need to validate any input. //$inscription = Inscription::findOrFail($id); if (!isset($request['step']) || $request['step'] < 1 && $request['step'] > 3) { return redirect('inscription.create'); } //actualizar estudiante if ($request['step'] == 1) { $inscription->student->update($request->all()); //actualizar grupo if ($inscription->group_id != $request['group_id']) { //buscar grupo anterior $inscription->group->students()->detach($inscription->student); //agregamos al nuevo $inscription->group_id = $request['group_id']; $group = Group::find($request['group_id']); $group->students()->attach($inscription->student); } $inscription->update($request->all()); //mostrar paso 2 return view('inscription.step2', compact('inscription')); } elseif ($request['step'] == 2) { if ($request['tutor_id'] != 0 && $inscription->tutor_id != $request['tutor_id']) { $inscription->student->tutor_id = $request['tutor_id']; $inscription->student->save(); } if ($inscription->student->tutor) { $inscription->student->tutor->update($request->all()); } else { $inscription->student->tutor_id = Tutor::create($request->all())->id; $inscription->student->save(); } //mostrar paso 3 ... return view('inscription.step3', compact('inscription')); } elseif ($request['step'] == 3) { if ($inscription->student->document) { $request['student_id'] = $inscription->student_id; $inscription->student->document->update($request->all()); } else { $request['student_id'] = $inscription->student_id; Document::create($request->all()); return redirect()->route('inscription.show', [$inscription]); } } return redirect('inscription'); }
/** * Create new Document instances in the DB, * Move the original file to document directory. * * @param $singleDimArr * @param $directoryPath * @param $projectID * @param $originalProjectSlug */ protected function moveDocumentsAndSaveToDB($singleDimArr, $directoryPath, $projectID, $originalProjectSlug) { foreach ($singleDimArr as $file) { if (!is_null($file)) { if ($file instanceof UploadedFile) { Document::create(['filename' => preg_replace('/[\\s]+/', '_', $file->getClientOriginalName()), 'project_id' => $projectID]); $file->move($directoryPath, preg_replace('/[\\s]+/', '_', $file->getClientOriginalName())); } else { // In the instance the user renames the project, move the saved documents to the new directory. $originalDirectory = public_path('documents/' . $originalProjectSlug); if (is_dir($originalDirectory)) { $originalFile = file_get_contents($originalDirectory . '/' . $file); file_put_contents($directoryPath . '/' . $file, $originalFile); } } } } }
/** * Execute the command. * * @return void */ public function handle() { $document = Document::create($this->data); event(new FeedableEvent('DocumentUploaded', $this->user, $document, null)); return $document; }
/** * [store description] * @param StoreDocumentRequest $request [description] * @return [type] [description] */ public function store(StoreDocumentRequest $request) { $document = Document::create(Input::all()); $url = URL::action('DocumentsController@show', [$document->id]); return $this->respondCreated('Document successfully created.', $url); }
public function store(Request $request) { $validator = $this->validator($request->all()); if ($validator->fails()) { Flash::error('Impossible d\'ajouter le document, veuillez vérifier les champs renseignés, ainsi que le format de votre document.'); return Redirect::back()->withErrors($validator->errors()); } $file = $request->file('file'); $ext = $file->getClientOriginalExtension(); $clientName = $file->getClientOriginalName(); $destPath = public_path() . '/files/documents'; $fileName = $request->course_id . Auth::user()->id . date('dmYHis') . rand(10000, 99999) . '.' . $ext; if ($file->move($destPath, $fileName)) { $title = $request->title; $description = $request->description; $user_id = Auth::user()->id; $course_id = $request->course_id; Document::create(['title' => $title, 'name' => $fileName, 'description' => $description, 'course_id' => $course_id, 'user_id' => $user_id]); Flash::success('Le document a bien été ajouté.'); } else { Flash::error('Une erreur est survenue. Veuillez réessayer. Si le problème persiste, contactez un administrateur.'); } return Redirect::back(); }
/** * Get the model instance or create one. * * @param string $file * @return mixed */ public function find($file) { return Document::whereName($file)->first() ?: Document::create(['author_id' => 1, 'name' => $file, 'content' => File::get($this->getPath($file))]); }