Skip to content
Kodivo is live on Product Hunt. Share your review
Back to Kodivo

Learning with AI

Understand the code you ask AI to write.

AI can draft a function or suggest how to build a feature. Knowing the basics helps you describe what should happen, check the result, and decide whether the solution fits your project.

Describe the behavior before the implementation.

A request like build a signup form leaves plenty of decisions open. Should it create an account, send an email, or just add an address to a waiting list? Which fields are required? What should happen if someone submits the form twice?

You can make those decisions before learning every line of PHP. Understanding inputs, validation, and stored data gives you the vocabulary to express them.

Build a waiting-list form with one email field. Validate the address, save each address once, and show a confirmation. Use the Laravel features already in this project. Leave account creation and email delivery out of this change.

That brief names the behavior you want and sets a boundary around the work. You can compare the suggested code with those requirements.

Check what a condition really means.

Code can look reasonable and still answer a different question from the one you intended. In PHP, a value and its type both matter. A number received as text is a useful example.

PHP: comparing a string with an integer
$count = '3';

var_dump($count == 3);
var_dump($count === 3);

Output

bool(true)
bool(false)

The quotes make '3' a string. == allows type conversion for this comparison; === also requires the types to match. The string and the integer therefore fail the strict comparison.

Knowing the difference lets you ask which type the application expects and where it should be checked. Trying both cases gives you something concrete to verify. The PHP comparison reference explains these operators.

Ask what each extra layer is for.

Suppose you need the total number of lessons across two chapters. A generated solution might wrap that calculation in a class. This example works, but the wrapper has only one job and one caller.

A wrapper used once
final class LessonCount
{
    public function total(array $counts): int
    {
        return array_sum($counts);
    }
}

$counts = [8, 12];
$counter = new LessonCount();
$total = $counter->total($counts);
Enough for this calculation
$counts = [8, 12];
$total = array_sum($counts);

Both examples produce 20. PHP already provides the operation we need.

A class can be useful when it owns counting rules that belong together or behavior used in several places. For this one calculation, the extra name and method give you more code to follow. Ask what current requirement makes that worthwhile.

Boilerplate is the setup code around a feature. Interfaces, factories, and additional packages each need a reason in the project you are building. Before accepting them, ask whether an existing function or framework feature already covers the job. See the PHP reference for array_sum.

Use what Laravel already provides.

Framework knowledge gives you useful questions to ask when a suggestion introduces custom code. For example, Laravel can validate a submitted email address with built-in rules.

Laravel: inside a controller with an injected Request
$data = $request->validate([
    'email' => ['required', 'email'],
]);

required makes the field mandatory. email checks the address format. When validation passes, $data contains the validated input. Laravel handles a failed validation through its standard response for the request.

This snippet checks input; it does not save an address or verify ownership of it. Those are separate requirements. If the project already puts these rules in a Form Request, keep using that convention. Reusing an established approach is often easier to maintain than introducing a parallel one.

The Laravel validation documentation covers controller validation and Form Requests. Reading the relevant part lets you check the suggestion against the framework your project actually uses.

Give the next prompt a smaller job.

A small change is easier to read and try out. Ask for one behavior at a time, then check the result before adding another feature. You can ask AI to explain an unfamiliar line using the values in your own example.

Show the smallest change for this behavior. Reuse the existing Laravel features and project conventions. Explain why any new class or dependency is needed, and show how I can check the result.

Before keeping a change, work through a few concrete questions:

  • What input does this code expect, and what should it return or change?
  • What happens with an empty value or invalid input?
  • Does this change only the behavior I asked for?
  • Can I explain why each new file or dependency is here?

When a change is beyond what you understand, ask for an explanation or a review before keeping it. Try changing one input in the example and predict the result. Run it, then investigate any difference.