1. Go to this page and download the library: Download lexal/laravel-stepped-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Lexal\HttpSteppedForm\Settings\FormSettingsInterface;
use Lexal\SteppedForm\Step\StepKey;
final class FormSettings implements FormSettingsInterface
{
public function getStepUrl(StepKey $key): string
{
// return step URL
}
public function getUrlBeforeStart(): string
{
// returns a URL to redirect to when there is no previously renderable step
}
public function getUrlAfterFinish(): string
{
// return a URL to redirect to when the form was finishing
}
}
$formSettings = new FormSettings();
use Lexal\HttpSteppedForm\SteppedFormInterface;
$this->app->when(CustomerController::class)
->needs(SteppedFormInterface::class)
->give('stepped-form.customer');
use Lexal\HttpSteppedForm\SteppedFormInterface;
final class CustomerController
{
public function __construct(private readonly SteppedFormInterface $form)
{
}
// POST /customers
public function start(): Response
{
return $this->form->start(new Customer(), /* nothing or customer id to split different sessions */);
}
// GET /customers/step/{step-key}
public function render(string $key): Response
{
return $this->form->render($key);
}
// POST /customers/step/{step-key}
public function handle(Request $request, string $key): Response
{
return $this->form->handle($key, $request);
}
// POST /customers/cansel
public function cancel(): Response
{
return $this->form->cancel(route('customer.index'));
}
}