コード例 #1
0
 /**
  * admin create new post
  * @author  Tran Van Moi
  * @since  2015/06/03
  * @return  response
  */
 public function postCreate()
 {
     $data = Input::all();
     $validator = Post::validate($data);
     if ($validator->fails()) {
         return Redirect::to('post/create')->withInput()->withErrors($validator);
     } else {
         $post = Post::create_post($data);
         if (count($post)) {
             return redirect('admin/post/create')->withInput()->with('create_status', ['status' => 'success', 'message' => 'Create a new post is success!']);
         } else {
             return redirect('admin/post/create')->withInput()->with('create_status', ['status' => 'danger', 'message' => 'Create a new post is failed! Please try again!']);
         }
     }
 }
コード例 #2
0
 /**
  * Show the form for editing the specified resource.
  * 
  * @param int $id        	
  * @return Response
  */
 public function postEdit($post_id = null)
 {
     $check_delete_post = Post::whereDelete_status(0)->whereId($post_id)->first();
     if ($check_delete_post) {
         $data = Input::all();
         $validator = Post::validate($data);
         if ($validator->fails()) {
             return Redirect::to('post/edit/' . $post_id)->withInput()->withErrors($validator);
         } else {
             $check_delete_post->title = $data['title'];
             $check_delete_post->content = $data['content'];
             $check_delete_post->category_id = $data['category'];
             if (Input::file('image')) {
                 $destination_path = './public/images/post/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $file_name = str_random(8) . '.' . $extension;
                 // renameing image
                 if (Input::file('image')->move($destination_path, $file_name)) {
                     if ($check_delete_post->image != "" && File::exists($destination_path . $check_delete_post->image)) {
                         File::delete($destination_path . $check_delete_post->image);
                     }
                     $check_delete_post->image = $file_name;
                 }
             }
             $check_delete_post->save();
             Session::flash('post_status', ['status' => 'success', 'message' => 'Edit post is success!']);
             return redirect()->back();
         }
     } else {
         return redirect('post/edit');
     }
 }