public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 200; $i++) {
         $new = TopicAnswer::create(array('tid' => $faker->randomDigitNotNull, 'author' => $faker->name, 'message' => $faker->paragraphs(5, true), 'place' => $faker->randomElement(array('web', 'api')), 'updated_at' => $faker->dateTime('now'), 'created_at' => $faker->dateTime('now')));
     }
 }
Example #2
0
 public function answer($tid = null)
 {
     if (empty($tid)) {
         return Response::json(['error' => true, 'message' => 'No topic id'], 404);
     }
     try {
         $t = Topic::findOrFail($tid);
     } catch (Exception $e) {
         return Response::json(['error' => true, 'message' => 'Topic not found'], 404);
     }
     $data = Input::only(['author', 'message']);
     $new = new TopicAnswer();
     $new->tid = $tid;
     $new->fill($data);
     $new->place = Input::has('api') ? 'api' : 'web';
     $new->save();
     $new->created_at->format('d-m-Y');
     return Response::json($new->toArray());
 }
 public function create()
 {
     foreach ($this->required as $required => $strlen) {
         if (!Input::has('tid')) {
             return Response::make(['error' => 'You must introduce a topic id to answer'], 404);
         }
         if (!Input::has($required) || strlen(Input::get($required)) < $strlen) {
             return Response::make(['error' => 'You must introduce a ' . $required . ' with ' . $strlen . ' of length...'], 404);
         }
     }
     $tid = Input::get('tid');
     try {
         $topic = Topic::findOrFail($tid);
     } catch (Exception $e) {
         return Response::make(['error' => true, 'message' => 'Sorry but that topic cannot be found!', 'data' => null], 404);
     }
     $new = new TopicAnswer();
     $new->tid = $tid;
     $new->fill(Input::only(['author', 'message']));
     $new->place = $this->place;
     $new->save();
     return Response::make(['success' => 'You just created a new answer!', 'answer' => $new->toArray(), 'topic' => $new->topic->toArray()], 404);
 }