/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $activity = array();
     $farm[] = Farm::with('plot.plant')->find($request->input('farmID'));
     $i = 0;
     foreach ($farm as $plot) {
         foreach ($plot->plot as $plot) {
             foreach ($plot->plant as $plant) {
                 if (Activity::with('activityType')->where('plant_id', '=', $plant->id)->first() != null) {
                     $tempActivity = Activity::with('activityType', 'plant.plot', 'user')->where('plant_id', '=', $plant->id)->get()->toArray();
                     foreach ($tempActivity as $temp) {
                         $activity[$i] = $temp;
                         $i++;
                     }
                 }
             }
         }
         $i++;
     }
     usort($activity, function ($a, $b) {
         $rdiff = strcmp($b['date'], $a['date']);
         if ($rdiff) {
             return $rdiff;
         }
         return strcmp($b['time'], $a['time']);
     });
     return $activity;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $taskCheck = TaskList::all();
     foreach ($taskCheck as $task) {
         $date = strtotime($task->date . ' ' . $task->time);
         $date2 = date("Y-m-d h:i:s");
         $date1 = strtotime($date2);
         if ($date1 > $date) {
             if ($task->status == "Remaining") {
                 $task->status = "Late";
                 $task->update();
             }
         }
     }
     $i = 0;
     $onlyTask = array();
     $farmID = $request->input('id');
     $farmList = Farm::with("plot.plant.taskList.workerMember")->where("id", "=", $farmID)->get();
     foreach ($farmList as $farm) {
         foreach ($farm->plot as $plot) {
             foreach ($plot->plant as $plant) {
                 foreach ($plant->taskList as $task) {
                     $date = date("Y-m-d");
                     if (strtotime($task->date) > strtotime($date . "- 7 days")) {
                         $onlyTask[$i] = $task;
                         $onlyTask[$i]->plantName = $plant->name;
                         $onlyTask[$i]->plotName = $plot->name;
                         $i++;
                     }
                 }
             }
         }
     }
     return $onlyTask;
 }
Example #3
0
 public function index(Manager $fractal, FarmTransformer $farmTransformer)
 {
     // show all
     $records = Farm::with('county.state', 'units')->get();
     $collection = new Collection($records, $farmTransformer);
     $data = $fractal->createData($collection)->toArray();
     return $this->respond($data);
 }