/** * @param array $input * @return mixed */ public function __invoke(array $input) { $user = $this->user->find($input['id']); if (!$user) { return $this->payload->setStatus(PayloadStatus::NOT_FOUND); } return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($this->user->find($input['id'])->shifts); }
/** * @param array $input * @return mixed */ public function __invoke(array $input) { if (!isset($input['month'])) { return $this->payload->setStatus(PayloadStatus::ERROR)->setInput($input)->setOutput("Month cannot be blank e.g. '?month=2016-02'"); } if (!\Datetime::createFromFormat('Y-m', $input['month'])) { return $this->payload->setStatus(PayloadStatus::ERROR)->setInput($input)->setOutput("Month is incorrect format e.g. '?month=2016-02'"); } $month_start = Carbon::createFromFormat('Y-m', $input['month'])->startOfMonth(); $month_end = Carbon::createFromFormat('Y-m', $input['month'])->endOfMonth(); $shifts = $this->shift->where('employee_id', '=', $input['id'])->where('start_time', '>=', $month_start)->where('start_time', '<=', $month_end)->get(); $hours = ['total_shifts' => $shifts->count(), 'total_hours' => 0]; foreach ($shifts as $shift) { $hours['total_hours'] += $shift->start_time->diffInHours($shift->end_time); } return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($hours); }
/** * @param array $input * @return mixed */ public function __invoke(array $input) { return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($this->user->all()); }
/** * @param array $input * @return mixed */ public function __invoke(array $input) { $users = ['data' => [['id' => 1, 'name' => 'Bob Smith', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 2, 'name' => 'Jon Jones', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 3, 'name' => 'Sally Black', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 4, 'name' => 'Tony Stark', 'role' => 'manager', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31']]]; return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($users); }
/** * @param array $input * @return mixed */ public function __invoke(array $input) { return $this->payload->setStatus(PayloadStatus::UPDATED)->setOutput($input); }