예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $data = $request->all();
     $rules = ['body' => 'required', 'tag_id' => 'required|numeric', 'tag' => 'required|min:3,max:254', 'access' => 'required|min:1,max:254', 'type' => 'required|min:3,max:254'];
     if ($data['access'] == 1) {
         $rules['name'] = 'required|min:3,max:254';
         $rules['email'] = 'required|email';
     } else {
         $rules['title'] = 'required|min:3,max:254';
     }
     $validator = \Validator::make($data, $rules);
     $json = array('status' => true, 'data' => null);
     if ($validator->fails()) {
         $json['status'] = false;
         $json['data'] = $validator->errors()->all();
     }
     if ($json['status']) {
         $comment = new \App\Comment($data);
         $comment->save();
     }
     if ($request->ajax()) {
         return response()->json($json);
     }
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $comment = new \App\Comment();
     $comment->user_id = \Auth::user()->id;
     $comment->comment_id = $request->comment_id;
     $comment->post_id = $request->post_id;
     $comment->content = $request->content;
     $comment->save();
     return $comment;
 }
 public function addComment(CommentRequest $request, $id)
 {
     if (\Auth::check()) {
         $user = \Auth::user();
         $post = \App\Post::findOrFail($id);
         $comment = new \App\Comment($request->all());
         $comment->user()->associate($user);
         $comment->post()->associate($post);
         $comment->save();
         return redirect('/post/' . $post->id);
     } else {
         return redirect('/auth/login');
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $bookings = \App\Booking::where('status', 'confirmed')->get();
     $fake_comments = file_get_contents("http://jsonplaceholder.typicode.com/comments");
     $fake_comments = json_decode($fake_comments, true);
     foreach ($bookings as $booking) {
         if (mt_rand(0, 1)) {
             $comments = \App\Comment::where('booking_id', $booking->id)->get();
             if (count($comments) > 0) {
                 continue;
             } else {
                 $comment = new \App\Comment();
                 $comment->user_id = $booking->customer_id;
                 $comment->property_id = $booking->property_id;
                 $comment->booking_id = $booking->id;
                 $comment->rating = mt_rand(1, 5);
                 $one_comment = $fake_comments[mt_rand(0, count($fake_comments) - 1)];
                 $comment->comment_text = $one_comment['body'];
                 $comment->written_at = date('Y-m-d H:i:s');
                 $comment->save();
             }
         }
     }
 }
 /**
  *  Add a Comment
  *
  */
 public function postComment()
 {
     $data = \Input::all();
     // Check Post exists
     if (empty($data['post_id'])) {
         return response()->json(['status' => 404, 'error' => "Post not Found"], 404);
     }
     $post = \App\Post::find($data['post_id']);
     if (!$post) {
         return response()->json(['status' => 404, 'error' => "Post not Found"], 404);
     }
     // Build Comment record
     $comment = new \App\Comment(['post_id' => $post->id, 'user_id' => \Auth::user()->id, 'body' => $data['comment_body']]);
     if ($comment->save()) {
         return response()->json(['status' => 200], 200);
     } else {
         return response()->json(['status' => 500, 'error' => "Saved Failed"], 500);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $tag_ids = [];
     $users = [];
     $nodes = [];
     static::nodeRecurse($nodes);
     for ($a = 1; $a <= 5; $a++) {
         $tag = new \App\Tag();
         $faker->seed($a + 10);
         $tag->name = $faker->word;
         $tag->save();
         $tag_ids[] = $tag->id;
     }
     $faker->unique(true);
     for ($b = 1; $b <= 20; $b++) {
         $user = new \App\User();
         $faker->seed($a);
         $user->name = $faker->unique()->userName;
         $user->email = $faker->unique()->email;
         $user->password = $faker->password;
         $user->save();
         $users[] = $user;
     }
     foreach ($users as $user) {
         $faker->seed($user->id);
         if ($faker->boolean(40)) {
             // Author
             $author = new \App\Author();
             $author->user()->associate($user);
             $author->name = $faker->name;
             $author->save();
             if ($faker->boolean(50)) {
                 $number_of_likes = $faker->numberBetween(1, count($users));
                 $faker->unique(true);
                 for ($c = 1; $c <= $number_of_likes; $c++) {
                     $like = new \App\Like();
                     $user_key = $faker->unique()->randomElement(array_keys($users));
                     $like->user()->associate($users[$user_key]);
                     $like->likeable()->associate($author);
                     $like->save();
                 }
             }
             if ($faker->boolean(20)) {
                 $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                 $faker->unique(true);
                 for ($d = 1; $d <= $number_of_reports; $d++) {
                     $report = new \App\Report();
                     $user_key = $faker->unique()->randomElement(array_keys($users));
                     $report->user()->associate($users[$user_key]);
                     $report->save();
                     $report->authors()->attach($author);
                 }
             }
             if ($faker->boolean(75)) {
                 // At leat 1 article
                 $article_count = $faker->numberBetween(1, 15);
                 for ($e = 1; $e < $article_count; $e++) {
                     $article = new \App\Article();
                     $article->author()->associate($author);
                     $article->title = $faker->sentence($faker->numberBetween(3, 10));
                     $article->body = $faker->paragraphs($faker->numberBetween(2, 8), true);
                     $article->node()->associate($faker->randomElement($nodes));
                     $article->save();
                     $article->tags()->sync($faker->randomElements($tag_ids, $faker->numberBetween(0, min(3, count($tag_ids)))));
                     if ($faker->boolean(10)) {
                         $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                         $faker->unique(true);
                         for ($f = 1; $f <= $number_of_reports; $f++) {
                             $report = new \App\Report();
                             $user_key = $faker->unique()->randomElement(array_keys($users));
                             $report->user()->associate($users[$user_key]);
                             $report->save();
                             $report->articles()->attach($article);
                         }
                     }
                     if ($faker->boolean(90)) {
                         $review = new \App\Review();
                         $user_key = $faker->randomElement(array_keys($users));
                         $review->user()->associate($users[$user_key]);
                         $review->reviewable()->associate($article);
                         $review->save();
                     }
                     if ($faker->boolean(69)) {
                         $number_of_likes = $faker->numberBetween(1, count($users));
                         $faker->unique(true);
                         for ($g = 1; $g <= $number_of_likes; $g++) {
                             $like = new \App\Like();
                             $user_key = $faker->unique()->randomElement(array_keys($users));
                             $like->user()->associate($users[$user_key]);
                             $like->likeable()->associate($article);
                             $like->save();
                         }
                     }
                 }
                 if ($faker->boolean(70)) {
                     // At leat 1 comment
                     $comment_count = $faker->numberBetween(1, 20);
                     for ($h = 1; $h < $comment_count; $h++) {
                         $comment = new \App\Comment();
                         $comment->article()->associate($article);
                         $comment->user()->associate($user);
                         $comment->body = $faker->paragraph(4, true);
                         $comment->save();
                         if ($faker->boolean(15)) {
                             $number_of_reports = $faker->numberBetween(1, round(count($users) / 3));
                             $faker->unique(true);
                             for ($i = 1; $i <= $number_of_reports; $i++) {
                                 $report = new \App\Report();
                                 $user_key = $faker->unique()->randomElement(array_keys($users));
                                 $report->user()->associate($users[$user_key]);
                                 $report->save();
                                 $report->comments()->attach($comment);
                             }
                         }
                         if ($faker->boolean(90)) {
                             $review = new \App\Review();
                             $user_key = $faker->randomElement(array_keys($users));
                             $review->user()->associate($users[$user_key]);
                             $review->reviewable()->associate($comment);
                             $review->save();
                         }
                         if ($faker->boolean(60)) {
                             $number_of_likes = $faker->numberBetween(1, count($users));
                             $faker->unique(true);
                             for ($j = 1; $j <= $number_of_likes; $j++) {
                                 $like = new \App\Like();
                                 $user_key = $faker->unique()->randomElement(array_keys($users));
                                 $like->user()->associate($users[$user_key]);
                                 $like->likeable()->associate($comment);
                                 $like->save();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public function comment(Request $request, $id)
 {
     $book = \App\Book::findOrFail($id);
     //      $user = \App\User::($id);
     $commented = $request->input('comment');
     $user = Auth::user();
     $comment = new \App\Comment();
     $comment->comment = $commented;
     $comment->save();
     $book->comments()->attach($comment);
     $user->comments()->attach($comment);
     return Redirect::back();
 }