예제 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $contentFile = contentFile::findOrFail($id);
     $validator = Validator::make($data = Input::all(), contentFile::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     /**
      * Check if Request param contains
      * status, if so activate
      * if not deactivate status
      */
     $status_exists = false;
     foreach ($data as $key => $value) {
         if ($key == 'status') {
             $status_exists = true;
         }
     }
     if ($status_exists) {
         $data['status'] = 1;
     } else {
         $data['status'] = 0;
     }
     $contentFile->update($data);
     return Redirect::route('admin.contentFiles.index');
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $contentFile = contentFile::findOrFail($id);
     $data = Input::all();
     //$validator=Validator::make($data,contentFile::$rules);
     /*
             if($validator->fails()){
                 return Redirect::back()->withErrors($validator)->withInput();
             }
     */
     $old_file_name = $contentFile->link;
     if (Input::hasFile('link')) {
         $dest = 'images/';
         $name = str_random(10) . '-' . Input::file('link')->getClientOriginalName();
         Input::file('link')->move($dest, $name);
         $old_file_name = $dest . '/' . $old_file_name;
         if (File::exists($old_file_name)) {
             File::delete($old_file_name);
         }
         $data['link'] = $name;
     }
     /**
      * Check if Request param contains
      * status, if so activate
      * if not deactivate status
      */
     $status_exists = false;
     foreach ($data as $key => $value) {
         if ($key == 'status') {
             $status_exists = true;
         }
     }
     if ($status_exists) {
         $data['status'] = 1;
     } else {
         $data['status'] = 0;
     }
     $contentFile->update($data);
     return Redirect::route('admin.contentFiles.index');
 }