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