cms/app/Services/FormService.php

59 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Services;
use App\Models\Form;
use App\Models\FormSubmission;
/**
* Service to handle Form creation and Submissions.
*/
class FormService
{
/**
* Store a newly created form.
*
* @param array $data Data for the new form.
* @return Form The created form instance.
*/
public function storeForm(array $data): Form
{
return Form::create($data);
}
/**
* Update the specified form.
*
* @param Form $form The form model to update.
* @param array $data The new data for the form.
* @return Form The updated form instance.
*/
public function updateForm(Form $form, array $data): Form
{
$form->update($data);
return $form;
}
/**
* Remove the specified form and its submissions.
*
* @param Form $form The form model to delete.
* @return bool True if successful.
*/
public function deleteForm(Form $form): bool
{
return (bool) $form->delete();
}
/**
* Remove a specific form submission.
*
* @param FormSubmission $submission The submission to delete.
* @return bool True if successful.
*/
public function deleteSubmission(FormSubmission $submission): bool
{
return (bool) $submission->delete();
}
}