2024-03-28 18:14:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Forms\Integration;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Integration\FormIntegrationsRequest;
|
2024-06-05 15:35:46 +02:00
|
|
|
use App\Http\Resources\FormIntegrationResource;
|
2024-03-28 18:14:30 +01:00
|
|
|
use App\Models\Forms\Form;
|
|
|
|
|
use App\Models\Integration\FormIntegration;
|
|
|
|
|
|
|
|
|
|
class FormIntegrationsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('auth');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index(string $id)
|
|
|
|
|
{
|
|
|
|
|
$form = Form::findOrFail((int)$id);
|
|
|
|
|
$this->authorize('view', $form);
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
$integrations = FormIntegration::query()
|
|
|
|
|
->where('form_id', $form->id)
|
|
|
|
|
->with('provider.user')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return FormIntegrationResource::collection($integrations);
|
2024-03-28 18:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create(FormIntegrationsRequest $request, string $id)
|
|
|
|
|
{
|
|
|
|
|
$form = Form::findOrFail((int)$id);
|
|
|
|
|
$this->authorize('update', $form);
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
/** @var FormIntegration $formIntegration */
|
2024-03-28 18:14:30 +01:00
|
|
|
$formIntegration = FormIntegration::create(
|
|
|
|
|
array_merge([
|
|
|
|
|
'form_id' => $form->id,
|
|
|
|
|
], $request->toIntegrationData())
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
$formIntegration->refresh();
|
|
|
|
|
$formIntegration->load('provider.user');
|
|
|
|
|
|
2024-03-28 18:14:30 +01:00
|
|
|
return $this->success([
|
|
|
|
|
'message' => 'Form Integration was created.',
|
2024-06-05 15:35:46 +02:00
|
|
|
'form_integration' => FormIntegrationResource::make($formIntegration)
|
2024-03-28 18:14:30 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(FormIntegrationsRequest $request, string $id, string $integrationid)
|
|
|
|
|
{
|
|
|
|
|
$form = Form::findOrFail((int)$id);
|
|
|
|
|
$this->authorize('update', $form);
|
|
|
|
|
|
|
|
|
|
$formIntegration = FormIntegration::findOrFail((int)$integrationid);
|
|
|
|
|
$formIntegration->update($request->toIntegrationData());
|
2024-06-05 15:35:46 +02:00
|
|
|
$formIntegration->load('provider.user');
|
2024-03-28 18:14:30 +01:00
|
|
|
|
|
|
|
|
return $this->success([
|
|
|
|
|
'message' => 'Form Integration was updated.',
|
2024-06-05 15:35:46 +02:00
|
|
|
'form_integration' => FormIntegrationResource::make($formIntegration)
|
2024-03-28 18:14:30 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy(string $id, string $integrationid)
|
|
|
|
|
{
|
|
|
|
|
$form = Form::findOrFail((int)$id);
|
|
|
|
|
$this->authorize('update', $form);
|
|
|
|
|
|
|
|
|
|
$formIntegration = FormIntegration::findOrFail((int)$integrationid);
|
|
|
|
|
$formIntegration->delete();
|
|
|
|
|
|
|
|
|
|
return $this->success([
|
|
|
|
|
'message' => 'Form Integration was deleted.'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|