コード例 #1
0
 /**
  * Store a newly created resource in storage.
  * POST /admin\document
  *
  * @return Response
  */
 public function store()
 {
     try {
         $rules = array('name' => 'required|unique:document', 'file' => 'required');
         $validation = Validator::make(Input::all(), $rules);
         if ($validation->fails()) {
             return Redirect::back()->withInput()->withErrors($validation->messages());
         }
         $doc = new Document();
         $doc->name = Input::get('name');
         $doc->description = Input::get('description');
         $file = Input::file('file');
         $path = '/documents';
         if (!File::exists(public_path() . $path)) {
             File::makeDirectory(public_path() . $path, 0777, true);
         }
         $fileName = Str::slug($doc->name) . '.' . $file->getClientOriginalExtension();
         $file->move(public_path() . $path, $fileName);
         $doc->path = $path . '/' . $fileName;
         if ($doc->save()) {
             return Redirect::back()->with('message', 'A dokumentum feltöltése sikerült!');
         } else {
             return Redirect::back()->withInput()->withErrors('A dokumentum feltöltése nem sikerült!');
         }
     } catch (Exception $e) {
         if (Config::get('app.debug')) {
             return Redirect::back()->withInput()->withErrors($e->getMessage());
         } else {
             return Redirect::back()->withInput()->withErrors('A dokumentum feltöltése nem sikerült!');
         }
     }
 }