/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     for ($x = 0; $x < $this->records; $x++) {
         //var_dump('NUMBER of Tags to create: ' . $this->random_number()) . '\n\n';
         for ($i = 0; $i < $this->random_number(); $i++) {
             #echo 'i: ' . $i. ' ==';
             $arr = ['point_id' => $this->random_point(), 'tags_id' => $this->random_tag(), 'created_by' => $this->getRandomUser()];
             //dd($arr);
             /*var_dump('loop nr: ' . $i) . '\n';
               var_dump($arr);*/
             \App\PointTag::create($arr);
             print 'Done ' . $this->records . ' entries was created';
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @NOTE That Tags should be a comma seperated list of tag_id's.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $validator = \Validator::make($request->all(), ['name' => 'required|min:3', 'description' => 'required|min:3', 'latitude' => 'required|min:3', 'longitude' => 'required|min:3', 'tags' => 'required', 'country' => 'required', 'files' => 'required']);
         if ($validator->fails()) {
             return $this->respondWithError($validator->errors());
         }
         $point = new Point();
         $point->name = $request->get('name');
         $point->description = $request->get('description');
         $point->longitude = $request->get('longitude');
         $point->latitude = $request->get('latitude');
         $point->country = $request->get('country');
         $point->created_by = Auth::user()->id;
         $point->updated_by = Auth::user()->id;
         if (!$point->save()) {
             return $this->respondWithError();
         }
         /* @param tags !NOTE! Tags should be a comma seperated list of tag id's */
         $tags = explode(',', $request->get('tags'));
         foreach ($tags as $t) {
             $tag = new PointTag();
             $tag->point_id = $point->id;
             $tag->created_by = Auth::user()->id;
             $tag->tags_id = $t;
             if (!$tag->save()) {
                 return $this->respondWithError('Could not add tag (' . $t . ')');
             }
         }
         $this->addFiles($request->get('files'));
         return Fractal::item($point, new PointTransformer())->responseJson(200);
     } catch (Exception $e) {
         return $this->respondInternalError();
     }
 }