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