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