action = $action; $this->request = $request; $this->model = $attendance; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Attendance $attendance, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $attendance = $attendance->create($attributes); return $attendance; } public function update(Attendance $attendance, array $request) { $attributes = $request; $attendance->update($attributes); return $attendance; } public function destroy(Attendance $attendance, array $request) { $attendance->delete(); return $attendance; } public function copy(Attendance $attendance, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $attendance = $attendance->replicate(); $attendance->created_at = Carbon::now(); $attendance->save(); return $attendance; } for ($i = 1; $i <= $count; $i++) { $new = $attendance->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $attendance; } }