Auqcion's avatar

Auqcion was awarded Best Answer+1000 XP

5mos ago

One clean approach is to store a snapshot of the form state after preFillEntry() and compare against it later. Instead of manually coding this in every FormObject, you can abstract it once in a base Form class:

public array $original = [];

public function snapshot(): void { $this->original = $this->toArray(); }

public function isDirty(array $only = []): bool { $current = $this->toArray();

if ($only) {
    $current = Arr::only($current, $only);
    $original = Arr::only($this->original, $only);
} else {
    $original = $this->original;
}

return $current !== $original;

}

Then call $this->form->snapshot() after preFillEntry() in mount().

Now every FormObject automatically gets a reusable isDirty() without repeating logic and you can even check only specific fields.

Auqcion's avatar

Auqcion wrote a reply+100 XP

5mos ago

You could also add something like this to keep the conversation moving:


One more thing worth noting: if your main goal is simply consistent formatting, you don’t actually need to manually match every exception in your schema. Laravel already maps most exceptions to proper HTTP codes, so you can just read the status from $exception->getStatusCode() when available:

$status = method_exists($exception, 'getStatusCode')
    ? $exception->getStatusCode()
    : 500;

That way your schema stays clean, and you only override types/messages when you really need custom behavior. It also means your global handler works automatically for future exceptions without updating match() every time.

This keeps your bootstrap/app.php small while still giving you full control over the output format.

Auqcion's avatar

Auqcion wrote a reply+100 XP

5mos ago

One clean approach is to store a snapshot of the form state after preFillEntry() and compare against it later. Instead of manually coding this in every FormObject, you can abstract it once in a base Form class:

public array $original = [];

public function snapshot(): void { $this->original = $this->toArray(); }

public function isDirty(array $only = []): bool { $current = $this->toArray();

if ($only) {
    $current = Arr::only($current, $only);
    $original = Arr::only($this->original, $only);
} else {
    $original = $this->original;
}

return $current !== $original;

}

Then call $this->form->snapshot() after preFillEntry() in mount().

Now every FormObject automatically gets a reusable isDirty() without repeating logic and you can even check only specific fields.

Auqcion's avatar

Auqcion wrote a reply+100 XP

5mos ago

I did something similar last year in Laravel using simple arrays and some helper functions to check word placement and overlaps. For frontend ideas or even logic inspiration, I looked at how puzzle generators work on a free games site that had word searches. Looking at those gave me a better idea of how to lay out the grid and handle diagonal or backward words. Kept it simple and did the rest manually.