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