コード例 #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $update = Update::find($id);
     if (Auth::check()) {
         $update = Update::withTrashed()->find($id);
     }
     return view('about.events.edit', compact('update'));
 }
コード例 #2
0
 public function update($id, Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required | min:3', 'headline' => 'sometimes|min:3', 'body' => 'sometimes | min:3', 'attachments' => 'required', 'published' => 'required|date', 'expires' => 'sometimes|after:' . $request->published]);
     if ($validator->passes()) {
         $post = Update::withTrashed()->find($id);
         $post->title = $request->title;
         $post->content = $request->body;
         $post->published_on = $request->published;
         $post->headline = $request->headline;
         if (isset($request->expires)) {
             $post->expires_on = $request->expires;
         }
         $post->category_id = $request->category;
         if ($post->save()) {
             if ($request->delete) {
                 foreach ($request->delete as $deletion) {
                     $attachment = Attachment::find($deletion);
                     $attachment->delete();
                 }
             }
             $request->featured = $request->featured == '' ? null : $request->featured;
             $post->featured = $request->featured;
             $post->save();
             if ($request->destroy) {
                 $post->delete();
             } else {
                 if (!is_null($post->deleted_at)) {
                     $post->restore();
                 }
             }
             $files = $request->file('attachments');
             if (count($files)) {
                 if (!is_dir($this->upload_dir . $post->id)) {
                     mkdir($this->upload_dir . $post->id);
                 }
                 $success = true;
                 foreach ($files as $file) {
                     if (!is_null($file) && $file->isValid()) {
                         if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                             $attachment = new Attachment();
                             $attachment->filename = $file->getClientOriginalName();
                             $attachment->size = $file->getClientSize();
                             $attachment->update_id = $post->id;
                             $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                             $attachment->save();
                         } else {
                             $success = false;
                         }
                     }
                 }
                 if ($success) {
                     return redirect('about/galleries/' . $post->id . '/edit');
                 }
             }
             return redirect('about/galleries');
         } else {
             return 'Error';
         }
     } else {
         return redirect('about/galleries/' . $post->id . '/edit')->withInput();
     }
 }
コード例 #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $post = Update::withTrashed()->find($id);
     $post->title = $request->title;
     $post->content = $request->body;
     $post->published_on = $request->published;
     $post->headline = $request->headline;
     if (isset($request->expires)) {
         $post->expires_on = $request->expires;
     }
     $post->category_id = $request->category;
     if ($post->save()) {
         if ($request->delete) {
             foreach ($request->delete as $deletion) {
                 $attachment = Attachment::find($deletion);
                 $attachment->delete();
             }
         }
         $request->featured = $request->featured == '' ? null : $request->featured;
         $post->featured = $request->featured;
         $post->save();
         if ($request->destroy) {
             $post->delete();
         } else {
             if (!is_null($post->deleted_at)) {
                 $post->restore();
             }
         }
         $files = $request->file('attachments');
         if (count($files)) {
             if (!is_dir($this->upload_dir . $post->id)) {
                 mkdir($this->upload_dir . $post->id);
             }
             $success = true;
             foreach ($files as $file) {
                 if (!is_null($file) && $file->isValid()) {
                     if ($file->move($this->upload_dir . $post->id, $file->getClientOriginalName())) {
                         $attachment = new Attachment();
                         $attachment->filename = $file->getClientOriginalName();
                         $attachment->size = $file->getClientSize();
                         $attachment->update_id = $post->id;
                         $attachment->type = pathinfo($this->upload_dir . $post->id . '/' . $file->getClientOriginalName(), PATHINFO_EXTENSION);
                         $attachment->save();
                     } else {
                         $success = false;
                     }
                 }
             }
             if ($success) {
                 return redirect('academylife/sports-news/' . $post->id . '/edit');
             }
         }
         return redirect('academylife/sports-news');
     } else {
         return 'Error';
     }
 }