Service class documentation for ArtisanPack UI Forms.
FormService
Handles form CRUD operations and retrieval.
Methods
use ArtisanPackUI\Forms\Services\FormService;
$formService = app(FormService::class);
getBySlug
Retrieve a form by its slug.
public function getBySlug(string $slug): ?Form
Example:
$form = $formService->getBySlug('contact');
getById
Retrieve a form by ID.
public function getById(int $id): ?Form
create
Create a new form.
public function create(array $data): Form
Example:
$form = $formService->create([
'name' => 'Contact Form',
'slug' => 'contact',
'description' => 'Contact us form',
'is_active' => true,
]);
update
Update an existing form.
public function update(Form $form, array $data): Form
delete
Delete a form and its related data.
public function delete(Form $form): bool
duplicate
Duplicate a form with all fields and settings.
public function duplicate(Form $form, ?string $newSlug = null): Form
Example:
$newForm = $formService->duplicate($form, 'contact-v2');
getActiveForms
Get all active forms.
public function getActiveForms(): Collection
FieldService
Manages form fields.
Methods
use ArtisanPackUI\Forms\Services\FieldService;
$fieldService = app(FieldService::class);
createField
Create a new field for a form.
public function createField(Form $form, array $data): FormField
Example:
$field = $fieldService->createField($form, [
'type' => 'text',
'name' => 'full_name',
'label' => 'Full Name',
'required' => true,
'order' => 1,
]);
updateField
Update an existing field.
public function updateField(FormField $field, array $data): FormField
deleteField
Delete a field.
public function deleteField(FormField $field): bool
reorderFields
Reorder fields for a form.
public function reorderFields(Form $form, array $fieldIds): void
Example:
$fieldService->reorderFields($form, [3, 1, 2, 5, 4]);
getFieldTypes
Get available field types.
public function getFieldTypes(): array
StepService
Manages multi-step form steps.
Methods
use ArtisanPackUI\Forms\Services\StepService;
$stepService = app(StepService::class);
create
Create a new step. When title is omitted, it defaults to "Step N".
public function create(Form $form, array $data = []): FormStep
update
Update a step.
public function update(FormStep $step, array $data): FormStep
delete
Delete a step. Its fields move to the previous step, or to no step if it was the first.
public function delete(FormStep $step): bool
reorder
Reorder a form's steps from an ordered array of step IDs.
public function reorder(Form $form, array $orderedIds): void
getById / getSteps / getFirstStep / getLastStep
Look up a form's steps.
public function getById(Form $form, int $stepId): ?FormStep
public function getSteps(Form $form): Collection
public function getFirstStep(Form $form): ?FormStep
public function getLastStep(Form $form): ?FormStep
convertToMultiStep / convertToSingleStep
Switch an existing form between single-step and multi-step. convertToMultiStep() creates a first step and moves every field into it. convertToSingleStep() detaches every field from its step and deletes the steps. Neither method changes is_multi_step, so update the flag in the same operation:
public function convertToMultiStep(Form $form): FormStep
public function convertToSingleStep(Form $form): void
$stepService->convertToMultiStep($form);
$form->update(['is_multi_step' => true]);
Note: Changing
is_multi_stepon a form that already has fields without converting it leaves the step data inconsistent, and the renderer can then show no fields. The admin form builder's Multi-Step Form toggle does both for you.
initializeMultiStep
Create a default first step only if the form has no steps yet.
public function initializeMultiStep(Form $form): ?FormStep
SubmissionService
Handles form submissions.
Methods
use ArtisanPackUI\Forms\Services\SubmissionService;
$submissionService = app(SubmissionService::class);
create
Create a new submission.
public function create(
Form $form,
array $data,
array $metadata = []
): FormSubmission
Example:
$submission = $submissionService->create($form, [
'name' => 'John Doe',
'email' => 'john@example.com',
'message' => 'Hello!',
], [
'source' => 'landing-page',
'utm_campaign' => 'summer2024',
]);
processFiles
Process uploaded files for a submission.
public function processFiles(
FormSubmission $submission,
array $files
): Collection
delete
Delete a submission and its files.
public function delete(FormSubmission $submission): bool
getForForm
Get submissions for a form with pagination.
public function getForForm(
Form $form,
int $perPage = 15,
array $filters = []
): LengthAwarePaginator
Example:
$submissions = $submissionService->getForForm($form, 20, [
'search' => 'john',
'start_date' => '2024-01-01',
'end_date' => '2024-12-31',
]);
NotificationService
Handles email notifications.
Methods
use ArtisanPackUI\Forms\Services\NotificationService;
$notificationService = app(NotificationService::class);
sendNotifications
Send all active notifications for a submission.
public function sendNotifications(FormSubmission $submission): void
shouldSendNotifications
(since 1.5.0)
Decide whether the notification pipeline should run for a submission. Quarantined submissions are suppressed by default; the decision passes through the ap.forms.submission.should_send_notifications filter so it can be overridden per submission.
public function shouldSendNotifications(FormSubmission $submission): bool
parseTemplate
Parse placeholders in a template.
public function parseTemplate(
string $template,
FormSubmission $submission
): string
Example:
$parsed = $notificationService->parseTemplate(
'Hello {name}, thank you for contacting us!',
$submission
);
formatAllFieldsAsTable
Format submission data as HTML table.
public function formatAllFieldsAsTable(
FormSubmission $submission
): string
getCcEmails
Get CC email addresses.
public function getCcEmails(FormNotification $notification): array
getBccEmails
Get BCC email addresses.
public function getBccEmails(FormNotification $notification): array
ConditionalLogicService
Evaluates conditional logic rules.
Methods
use ArtisanPackUI\Forms\Services\ConditionalLogicService;
$conditionService = app(ConditionalLogicService::class);
evaluateConditions
Evaluate conditions against form data.
public function evaluateConditions(
?array $conditions,
array $formData
): bool
Example:
$isVisible = $conditionService->evaluateConditions([
'logic' => 'and',
'rules' => [
['field' => 'country', 'operator' => 'equals', 'value' => 'US'],
],
], $formData);
getVisibleFields
Get fields visible for current form state.
public function getVisibleFields(Form $form, array $formData): Collection
isFieldVisible
Check if a specific field is visible.
public function isFieldVisible(FormField $field, array $formData): bool
ExportService
Handles data export operations.
Methods
use ArtisanPackUI\Forms\Services\ExportService;
$exportService = app(ExportService::class);
toCsv
Export submissions to CSV.
public function toCsv(
Form $form,
array $options = []
): string
Example:
$csv = $exportService->toCsv($form, [
'start_date' => now()->subMonth(),
'end_date' => now(),
]);
toArray
Export submissions to array.
public function toArray(
Form $form,
array $options = []
): array
IntegrationService
Manages third-party integrations.
Methods
use ArtisanPackUI\Forms\Services\IntegrationService;
$integrationService = app(IntegrationService::class);
getAvailableIntegrations
Get registered integrations.
public function getAvailableIntegrations(): array
processSubmission
Process submission through integrations.
public function processSubmission(FormSubmission $submission): void

