/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $comments = \App\Comment::all();
     $fake_replies = file_get_contents("http://jsonplaceholder.typicode.com/comments");
     $fake_replies = json_decode($fake_replies, true);
     foreach ($comments as $comment) {
         if (mt_rand(0, 1)) {
             $replies = \App\Reply::where('reply_to_id', $comment->id)->get();
             if (count($replies) > 0) {
                 continue;
             } else {
                 $reply = new \App\Reply();
                 $reply->reply_to_id = $comment->id;
                 $one_reply = $fake_replies[mt_rand(0, count($fake_replies) - 1)];
                 $reply->reply_text = $one_reply['body'];
                 $reply->save();
             }
         }
     }
 }
Beispiel #2
0
 Route::get('/booking/comment/reply/{comment_id}', function ($commend_id) {
     $comment = Comment::find($commend_id);
     $property = Property::find($comment->property_id);
     $author = User::find($comment->user_id);
     return view('new_reply', ['comment' => $comment, 'property' => $property, 'author' => $author]);
 });
 Route::post('/booking/comment/reply', function (Request $request) {
     $data = $request->all();
     $validator = Validator::make($request->all(), ['comment_id' => 'required|numeric|min:1|integer']);
     if ($validator->fails()) {
         return redirect(url('/booking/comment/reply/' . $data['comment_id']))->withInput()->withErrors($validator);
     }
     $reply = new \App\Reply();
     $reply->reply_to_id = $data['comment_id'];
     $reply->reply_text = $data['reply'];
     $reply->save();
     $comment = Comment::find($data['comment_id']);
     return redirect(url('/property/' . $comment->property_id));
 });
 Route::post('/property/booking_requests/confirm', function (Request $request) {
     $data = $request->all();
     $validator = Validator::make($request->all(), ['booking_id' => 'required|numeric|min:1|integer']);
     if ($validator->fails()) {
         return redirect(url('/property/booking_requests'))->withInput()->withErrors($validator);
     }
     $booking = \App\Booking::find($data['booking_id']);
     $select_statement = 'SELECT * FROM bookings WHERE ' . "'" . $booking->start . "'" . ' <= bookings.end AND ' . "'" . $booking->end . "'" . ' >= start AND bookings.status = ' . "'" . 'requested' . "' AND bookings.id <> " . $booking->id;
     $overlapping_bookings = DB::select($select_statement);
     if (count($overlapping_bookings) > 0) {
         foreach ($overlapping_bookings as $overlapping_booking) {
             $overlap_book = \App\Booking::find($overlapping_booking->id);