update($data); return $customPostType; } /** * Remove the specified custom post type and its associated fields. * * @param CustomPostType $customPostType The CPT model to delete. * @return bool True if successful. */ public function deleteCustomPostType(CustomPostType $customPostType): bool { return (bool) $customPostType->delete(); } /** * Store a newly created custom field for a custom post type. * * @param CustomPostType $customPostType The parent CPT. * @param array $data Data for the new field. * @return CustomField The created field instance. */ public function storeCustomField(CustomPostType $customPostType, array $data): CustomField { return $customPostType->fields()->create($data); } /** * Update the specified custom field. * * @param CustomField $customField The field model to update. * @param array $data The new data. * @return CustomField The updated model instance. */ public function updateCustomField(CustomField $customField, array $data): CustomField { $customField->update($data); return $customField; } /** * Remove the specified custom field. * * @param CustomField $customField The field model to delete. * @return bool True if successful. */ public function deleteCustomField(CustomField $customField): bool { return (bool) $customField->delete(); } /** * Reorder fields for a custom post type based on provided data. * * @param array $fieldsData Array of field IDs and their new sort orders. * @return void */ public function reorderFields(array $fieldsData): void { foreach ($fieldsData as $fieldData) { CustomField::where('id', $fieldData['id'])->update(['sort_order' => $fieldData['sort_order']]); } } }