How to Add AI Automation to Your Existing Laravel App Without a Rewrite
Ask a few developers about adding AI to a Laravel app that an agency built years ago, and at least one of them will tell you to rebuild it first. Founders bring me that quote all the time. When I open the code, I mostly find an app that needs a working queue and a few small additions, and the rebuild would have spent months recreating features the business already had.
I am Prashant Singh, and I have written PHP and Laravel for clients since 2014. These days most of my work is adding automation and AI to systems that companies are already running. At Manomay Informatics, the automation I built with Zapier and the OpenAI API cut manual operations by 80% for enterprise clients, and it ran on top of the tools those clients already used. This guide is the method I follow on that kind of project, with the code, the version rules and the few cases where I do tell a client to rebuild.
Key Takeaways
- In 2026, PHP runs 69.2% of websites whose server-side language is known (W3Techs), so most AI features will be added to apps that already exist.
- Keep the AI call off the web request. Your existing code queues a job, the job calls the model, and the answer is saved for a person to check.
- The official Laravel AI SDK needs PHP 8.3 and Laravel 12 or 13. Older apps can call the same models through Laravel’s HTTP client today.
- Start with one back-office workflow and fix the queue first. Measure the hours saved before you add a second one.
Can You Add AI to an Existing Laravel App Without Rebuilding It?
Yes. In 2026, PHP is the server-side language of 69.2% of the websites where W3Techs can detect one, according to the W3Techs PHP usage statistics (retrieved 2026-10-29). A big share of the software businesses want AI inside is PHP already, and Laravel ships with every part an AI feature needs.
Think about what an AI feature does once you take the buzzwords out. It reads some records from your database and sends them to a model over HTTP. Then it waits a few seconds for the reply and saves whatever comes back. Laravel has handled every one of those steps for years. You read the data with Eloquent, and the HTTP client that comes with the framework sends the request. The waiting is where the queue comes in, because a model can take ten or twenty seconds to answer and no page should keep a visitor waiting that long.
In 2025, Gartner predicted that over 40% of agentic AI projects will be cancelled by the end of 2027, in its press release Gartner Predicts Over 40% of Agentic AI Projects Will Be Canceled by End of 2027 (retrieved 2026-10-29). Gartner blamed escalating costs and unclear business value, and it also said that connecting agents to legacy systems is technically complex and can disrupt workflows. I take that as a reason to keep the AI part in its own small corner of the codebase, where a failure stays contained and your checkout keeps working.
Why Do Developers Keep Recommending a Rewrite?
In 2000, Joel Spolsky called rewriting code from scratch the single worst strategic mistake a software company can make, in his essay Things You Should Never Do, Part I (retrieved 2026-10-29). Twenty-six years later I agree with him, and founders keep receiving rebuild quotes for apps that need far less work.
A rewrite is easier for the person quoting it. They get to work in fresh code with a bigger estimate, and they never have to open the controllers a previous agency left behind. Your feature work stops for months while the new version catches up with the old one. Every odd case the old code handled without anyone noticing has to be found again, and customers find most of them first.
In 2025, MIT’s Project NANDA reported in The GenAI Divide: State of AI in Business 2025 (as covered by Fortune, retrieved 2026-10-29) that about 95% of enterprise generative AI pilots had little or no measurable effect on profit and loss. Tools bought from specialised vendors or built with partners worked about 67% of the time, and internal builds succeeded only one third as often. The same study found the biggest return in back-office automation, which is the work an existing Laravel app is full of.
There are cases where I recommend a rebuild, and I cover them near the end of this guide. For most apps I see, the AI work and the clean-up work can happen in the same codebase, one workflow at a time.
What Does Bolting AI Onto a Laravel App Look Like?
The pattern I use changes your existing code in one place. Something that already happens in the app, like a new support ticket or a saved invoice, dispatches a queued job. The job sends the data to the AI provider, and the reply goes into new columns that your app can show to staff.
- Pick a trigger that already exists in the app, such as a new ticket or a saved order.
- Dispatch a queued job from that trigger. This is the only line of old code you change.
- Inside the job, call the model through one class that has a timeout and retries.
- Save the result to new columns or a new table so that no existing screen breaks.
- Show the result to a person before it reaches a customer or touches money.

Step 2 in code is a single line in the boot method of AppServiceProvider. The rest of your Ticket model and controllers stay as they are.
use App\Jobs\SummariseTicket;
use App\Models\Ticket;
Ticket::created(function (Ticket $ticket) {
SummariseTicket::dispatch($ticket->id);
});
The job does the slow part on a queue worker. This version uses Laravel’s own HTTP client, so it runs on Laravel 8 and above with PHP 8.0 or newer, and you do not need a new package. Add OPENAI_API_KEY and OPENAI_MODEL to your .env and map them in config/services.php under an openai key, then add the two new columns with a migration.
<?php
namespace App\Jobs;
use App\Models\Ticket;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class SummariseTicket implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3;
public $backoff = 60;
public function __construct(public int $ticketId)
{
}
public function handle(): void
{
$ticket = Ticket::findOrFail($this->ticketId);
$response = Http::withToken(config('services.openai.key'))
->timeout(60)
->post('https://api.openai.com/v1/chat/completions', [
'model' => config('services.openai.model'),
'response_format' => ['type' => 'json_object'],
'messages' => [
[
'role' => 'system',
'content' => 'Summarise this support ticket in two lines and tag it as billing, bug or other. Reply in JSON with the keys summary and tag.',
],
['role' => 'user', 'content' => $ticket->body],
],
])
->throw()
->json();
$result = json_decode($response['choices'][0]['message']['content'], true);
$ticket->update([
'ai_summary' => $result['summary'] ?? null,
'ai_tag' => $result['tag'] ?? null,
]);
}
}
Two settings in this job matter more than the prompt. With $tries and $backoff, a timeout from the provider gets retried a minute later, up to three times. The throw() call turns an error response into a failed job that shows up in your failed_jobs table, which is where you will spot problems well before a customer writes in about them.
Which Laravel Version Do You Need for AI?
Any Laravel version that can make an HTTP request can call an AI model, and the official SDK adds its own version rules on top. In 2026, version 1.3.0 of the laravel/ai package on Packagist needs PHP 8.3 and Laravel 12 or 13 (retrieved 2026-10-29), so a Laravel 12 app still on PHP 8.2 has to move up a PHP version first.
| Laravel | PHP | Security fixes until | Can install laravel/ai? |
|---|---|---|---|
| 10 | 8.1 to 8.3 | 4 Feb 2025 (ended) | No. Use the HTTP client job above |
| 11 | 8.2 to 8.4 | 12 Mar 2026 (ended) | No. Use the HTTP client job above |
| 12 | 8.2 to 8.5 | 24 Feb 2027 | Yes, on PHP 8.3 or newer |
| 13 | 8.3 to 8.5 | 17 Mar 2028 | Yes |
If your app is on Laravel 8, 9, 10 or 11, the job above works today, and you can ship your first AI feature before you upgrade anything. Plan the upgrade anyway. Laravel 11 stopped getting security fixes on 12 March 2026, according to the Laravel 13.x release notes (retrieved 2026-10-29), and an app that sends customer data to an outside API should be on a framework that still gets patched. The release notes say most apps can move to Laravel 13 without changing much code. Coming from 8 or 9 takes longer, so I quote that upgrade as a separate piece of work.
On Laravel 12 or 13 with PHP 8.3, the Laravel AI SDK gives you a cleaner version of the same job. Install it with composer require laravel/ai, publish its config, and create an agent class with php artisan make:agent TicketTriage --structured. The agent holds the instructions and the shape of the answer you expect back.
<?php
namespace App\Ai\Agents;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Promptable;
use Stringable;
class TicketTriage implements Agent, HasStructuredOutput
{
use Promptable;
public function instructions(): Stringable|string
{
return 'Summarise the support ticket in two lines and tag it as billing, bug or other.';
}
public function schema(JsonSchema $schema): array
{
return [
'summary' => $schema->string()->required(),
'tag' => $schema->string()->required(),
];
}
}
Inside the job, the HTTP call shrinks to a few lines. Passing two providers means the request moves to Anthropic on its own when OpenAI is down or rate limited.
use App\Ai\Agents\TicketTriage;
use Laravel\Ai\Enums\Lab;
$response = TicketTriage::make()->prompt(
$ticket->body,
provider: [Lab::OpenAI, Lab::Anthropic],
);
$ticket->update([
'ai_summary' => $response['summary'],
'ai_tag' => $response['tag'],
]);
The SDK also gives you TicketTriage::fake() for tests, so your test suite can check the feature without calling a paid API on every run.
Where Should You Add AI First in an Existing App?
Start in the back office, wherever staff copy information from one screen into another. MIT’s 2025 GenAI Divide research found the biggest return from generative AI in back-office automation (retrieved 2026-10-29), and my own client work points the same way. Below are the places I check first in any Laravel app, with what I built in each.
The inbox
If someone on your team reads emails all day and types the details into your app, that is the first job to automate. On AMRIOP, a receipt management SaaS with a Laravel backend, we rebuilt onboarding around single sign-on with a mailbox permission granted at signup. Receipts now get fetched and sorted on their own, and the manual steps per receipt went from four or five down to zero. If your business runs on Microsoft 365, my guide to reading, filtering and saving emails with the Graph API in Laravel covers the fetching half of this work.
For the AI half, my guide to AI email triage for Laravel shows the webhook, the queued job and the reply drafts in code.
CRM records and invoices
At Cityfurnish, one of India’s largest furniture rental platforms, I led the team that built the Zoho CRM integration and automated the invoice system. Rental schedules there changed every day, so invoice status had to be checked against the schedule in code. I would let a model draft the note that goes out with an invoice, and I would keep the amount itself in plain PHP where a test can check it.
Scheduling and calendars
At Manomay Informatics I built a Google Calendar integration app and connected Zapier and the OpenAI API across client workflows, which is where the 80% drop in manual operations came from. The full story, with what we automated and in what order, is in my AI automation case study. If you only need the calendar part, start with how to integrate the Google Calendar API with Laravel.
Customer status updates
For I Siente, an Indian e-commerce client, I replaced WhatsApp notifications billed through a reseller with a direct Meta WhatsApp Business Platform connection, driven by Shiprocket status webhooks. Customers now get 10 status updates per order where they used to get 4, at ₹1.10 where it used to cost ₹7.00. This project used no AI model, and I include it because many of the AI requests I get turn out to be two systems that need a webhook between them, and a webhook costs far less to run than any model.
Support replies
A model that reads a ticket along with the customer’s order history can draft a reply for an agent to approve. This is the feature founders ask for most, and it is also the one most likely to time out, because it depends on a fast query for that history. I wrote about one such case in five signs your backend can’t support the AI automation you want. When a draft is ready, a message to the team channel helps, and my guide on posting messages to Slack from Laravel covers that part.

What Does Your App Need Before AI Goes In?
Your app needs a queue that runs all the time and queries that stay fast at the volume automation creates. On Let’s Calendar, a bulk calendar invite SaaS I built, moving contact import into chunked background jobs took capacity from about 5,000 contacts, which timed out at around 15 minutes, to 101,096 contacts imported in under a minute on the same server.
The import ran no AI at all, and I show it here because an AI feature puts the same kind of load on your app. A workflow that fires on every new order calls the model, reads the database and writes back hundreds of times a day with nobody watching. If the queue is missing or the worker dies at night, the work piles up quietly. Before I write the first prompt, I go through this list.
- A queue worker kept alive by Supervisor, plus a
failed_jobstable that someone looks at each week. My guide to setting up Supervisor on AWS EC2 covers the worker part. - No N+1 queries on the pages and jobs the AI will touch. The fix is in what the N+1 query problem is and how eager loading solves it.
- One table that holds the true version of each customer record, so the model never reads a stale copy from a spreadsheet.
- API keys in
.envand the config files, with a monthly spending limit set in the AI provider’s dashboard. - A log of every prompt and response for the first few weeks, so you can see what the model did when someone asks.
- A server you control and can update. If you are moving to a VPS, my VPS setup guide for Laravel on Ubuntu walks through it.
If an agency built your app and has since left, sort out the handover before you work through this list. My 30-day checklist for a Laravel app inherited from an agency covers the accounts and passwords to take over first. To find out whether your app is ready for AI at all, read the seven signs your Laravel app needs AI automation.
How Do You Stop AI From Making Expensive Mistakes?
Put a person between the model and anything that costs money or reaches a customer. In the Stack Overflow 2025 Developer Survey, AI section (retrieved 2026-10-29), 46% of developers said they distrust the accuracy of AI output and 33% said they trust it. Answers that are almost right were the biggest frustration for 66% of them.
If the people who build with these models every day trust them that little, your customers should not get raw model output either. In my builds the model writes into a draft column, and a staff member presses approve before anything goes out. After a few weeks you can see which kinds of drafts get approved without edits, and only those move to sending on their own.
Structured output does a lot of the safety work for you. When the model has to return a tag from a fixed list, your code can reject anything outside that list and retry the job. I also store the raw response next to the parsed result, because when a client asks why the system tagged an invoice as a refund, the raw reply answers that in seconds.
Some data should never leave your server, such as medical notes or contracts under NDA. For that, you can run an open model on your own VPS and point the job at it. I set one up in installing Ollama on a VPS with Apache and SSL, and the Laravel AI SDK lists Ollama as a supported text provider, so the agent code above barely changes.
For features where staff need to see the AI result as soon as the job finishes, broadcast an event from the job and push it to the screen. My guide to real-time sync with WebSockets and Pusher shows how that works in Laravel.
How Should You Roll Out the First AI Feature?
Roll out one workflow, measure it, and only then pick the next one. The 80% reduction at Manomay came from a series of single workflows done in that order, as the case study explains. I follow the same order on every automation project.
- Write down one workflow and count the minutes your staff spend on it in a normal week.
- Fix the queue, the worker and any slow queries that workflow depends on.
- Build the job behind a feature flag, with the output visible to staff only.
- Run it in draft mode for two weeks and compare the AI output with what staff did by hand.
- Switch it on, count the minutes again, and write the number down where the whole team can see it.
Without a before number you cannot tell whether the feature paid for itself, and the next budget conversation turns into opinions. Pricing depends on how many systems the workflow touches, and I break the cost drivers down in what AI automation costs a business.
When Is a Rewrite the Right Call?
I recommend a rebuild when the problems sit in the foundation, where no amount of AI work on top would help. In 2026, with Laravel 10 and 11 both out of security support per the Laravel 13.x release notes (retrieved 2026-10-29), an old version alone does not count as one of those reasons. In almost every app I have opened, the upgrade cost a fraction of what a rewrite would have.
These are the situations where I have told clients to rebuild, or where I would.
- The app runs on a PHP version that current Laravel cannot use, every upgrade step breaks something, and there are no tests to catch the breakage.
- The database design is wrong for how the business works now, for example one table per customer, or money stored as text.
- The business has changed so much that most screens in the app go unused and staff work around it in spreadsheets.
- Nobody can deploy the app safely, and each release means someone editing files on the live server by hand.
Even when a rebuild is the right answer, I would still add the first AI feature to the old app if it saves staff time this quarter. A rebuild takes months, and the queued job you write now can move to the new codebase almost unchanged, because it only talks to the rest of the app through a model ID and a few columns.
To work out which side of that line your app sits on, go through my guide to legacy PHP modernization vs rewrite.
Frequently Asked Questions
Do I need to upgrade Laravel before adding AI to my app?
You can add your first AI feature on Laravel 8 or newer by calling the model through the HTTP client inside a queued job. The official laravel/ai SDK needs PHP 8.3 and Laravel 12 or 13. Plan the upgrade either way, since Laravel 11 security fixes ended on 12 March 2026.
Which AI provider should a Laravel app use?
Any provider with an HTTP API will work. The Laravel AI SDK supports OpenAI, Anthropic, Gemini, Mistral, Ollama and several others for text. Keep every model call inside one class or agent, so you can switch providers or add a fallback provider without touching the rest of the app.
Will AI calls slow down my Laravel app?
The calls run on a queue worker, so the page your user sees responds as fast as it did before. A model can take ten or twenty seconds to reply, which is why the call belongs in a queued job with a timeout and retries. Keep the worker alive with Supervisor.
Is it safe to send customer data to an AI API?
Send only the fields the task needs, read the provider’s data retention terms, and set a monthly spending limit. For data that must stay on your own server, run an open model with Ollama on your VPS. The Laravel AI SDK lists Ollama as a supported text provider.
How do I know if the AI automation worked?
Count the minutes your staff spend on the workflow in a normal week before you build anything, then count again after launch. At Manomay Informatics, measuring workflow by workflow is how we could show an 80% drop in manual operations for enterprise clients.
Want to Know if Your Laravel App Can Take AI as It Is?
Send me the Laravel version from your composer.json and one line about the workflow that eats your team’s time. I will tell you whether it can be done on the app you have today, and if your app needs a rebuild first, I will tell you that as well. Message me on WhatsApp, or use the email and phone details on the contact page.
Written by Prashant Singh, a freelance Laravel and PHP developer in Kanpur, India. He has built production web apps since 2014 for clients in the US, UK, Australia and Israel, and now spends most of his time adding AI automation to systems businesses already run.
Sources
- W3Techs, “Usage statistics of PHP as server-side programming language on websites,” retrieved 2026-10-29
- Gartner, “Gartner Predicts Over 40% of Agentic AI Projects Will Be Canceled by End of 2027,” 25 June 2025, retrieved 2026-10-29
- Joel Spolsky, “Things You Should Never Do, Part I,” Joel on Software, 6 April 2000, retrieved 2026-10-29
- MIT Project NANDA, “The GenAI Divide: State of AI in Business 2025,” as reported by Fortune, August 2025, retrieved 2026-10-29
- Packagist, “laravel/ai,” version 1.3.0 requirements, retrieved 2026-10-29
- Laravel, “Release Notes, Laravel 13.x,” support policy, retrieved 2026-10-29
- Laravel, “Laravel AI SDK,” Laravel 13.x documentation, retrieved 2026-10-29
- Stack Overflow, “2025 Developer Survey: AI,” retrieved 2026-10-29
