reducktion/socrates
Socrates is a Laravel package for building dynamic questionnaires, surveys, and forms. It offers an Eloquent-friendly way to define questions, capture responses, and manage submissions, making structured Q&A flows easy to add to your app.
Socrates v2.0.0 is a breaking release. Start by confirming your app runs PHP 8.1+ and that you are not relying on the removed Laravel facade, validation rule, Luxembourg support, Carbon, or old Gender/Country string constants.
Gender and Country are now enums. Use them for type-safe comparisons instead of the removed string constants.First use case: validating a supported national ID during onboarding, then extracting country/gender metadata through the new enums. In Laravel, put this behind a small adapter or custom validation rule rather than calling package classes from controllers.
Wrap package usage behind your own adapter. Since the Laravel integration was removed, keep Socrates calls in one service class. This makes future package changes, country support changes, or a v1 fallback for Luxembourg easier to isolate.
final class IdVerificationService
{
public function verify(string $id, Country $country): IdResult
{
// Use the package validator/extractor here.
// Normalize input before calling Socrates if the package expects it.
}
}
Create a custom Laravel validation rule. Replace the removed package validation rule with your own rule that calls Socrates and reports failures through Laravel’s validator.
final class SocratesIdRule implements ValidationRule
{
public function __construct(private Country $country) {}
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$result = app(IdVerificationService::class)->verify((string) $value, $this->country);
if (! $result->isValid()) {
$fail('The :attribute is not a valid national ID.');
}
}
}
Use it from form requests:
'id_number' => ['required', 'string', new SocratesIdRule(Country::US)],
Use enum casts for persistence. Store the enum value in the database and cast it back in Eloquent:
protected $casts = [
'country' => Country::class,
'gender' => Gender::class,
];
When comparing, use enum cases:
if ($result->gender() === Gender::Female) {
// ...
}
Persist with ->value only when writing to storage/API payloads:
$model->country = $country->value;
Migrate old string constants. Any config, database seed, API response, or validation rule that used the old Gender/Country strings must move to enum cases or enum values. For database rows, add a mapping migration before switching code.
Replace Carbon expectations. v2 removed the Carbon dependency. If your extraction code assumed Carbon instances for dates, update it to work with native date/time objects or convert them at your application boundary.
Handle Luxembourg explicitly. Since the Luxembourg validator and extractor are removed, multi-country flows should either reject Luxembourg at the country-selection step or route it to a separate implementation. Do not rely on a generic “supported country” check returning Luxembourg.
Test against supported countries only. Add tests for each country you actually use, plus a test that unsupported countries fail predictably. This is especially important after removing Luxembourg and changing enum-based APIs.
Socrates::... or rule-class usage with your own adapter/rule.^1 if you need removed features. If you depend on the Laravel facade, built-in validation rule, Luxembourg support, Carbon, or old string constants, do not upgrade yet.->value at serialization boundaries and enum cases internally.Carbon or call Carbon-only methods on extracted dates.php artisan optimize:clear and composer dump-autoload after upgrading to catch stale aliases or cached config.composer why-not.How can I help you explore Laravel packages today?