It’s definitely frustrating when AI tools don’t follow your framework conventions or replicate code with your exact component structure. Tools like Cursor can generate generic code fast, but they often need careful guidance and sometimes still ignore architectural/organizational details—especially when it comes to custom Blade and UI component use.
Here's how you can get closer to “copy exact” results:
1. Provide Sample Files Explicitly
AI tools need clear references. Rather than telling it to “do like Users,” try pasting or linking to the relevant parts:
- The
PubsLivewire component class - The
PubsBlade view, especially the table and button code - The button Blade components (
resources/views/components/button/) - Example use of LivewireAlert
For example:
Please generate a Livewire CRUD for `Cars`. Use exactly the same structure as below for the table and actions.
Table extract from `Pubs`:
<x-table>
<x-slot name="head">
<x-table.heading sortable>...</x-table.heading>
<x-table.heading>Actions</x-table.heading>
</x-slot>
<x-slot name="body">
@foreach ($pubs as $pub)
<x-table.row>
...
<x-table.cell>
<x-button.edit wire:click="edit({{ $pub->id }})" />
<x-button.delete wire:click="delete({{ $pub->id }})" />
</x-table.cell>
</x-table.row>
@endforeach
</x-slot>
</x-table>
Be explicit: “DO NOT create buttons inline, use the above Blade components like x-button.edit etc.”
2. Demand Rewrites For Non-Conformant Output
If Cursor produces inline or custom HTML, ask:
- “Rewrite using only Blade buttons from
resources/views/components/button/for all actions.”
3. SweetAlert and LivewireAlert
Again, show how you trigger success:
$this->emit('alert', [
'type' => 'success',
'message' => 'Car added successfully.',
'position' => 'top-end',
'timer' => 3000,
'toast' => true,
]);
Then: “Always use this alert pattern from now on.”
4. Prepare a Skeleton File for Cursor to Fill
Instead of asking for a whole new file, paste a copy of your Pubs CRUD and say,
“Rename model and properties for ‘Cars’ (or Pets), but keep all structure and component usage identically.”
5. Manual Tweaks are (For Now) Unavoidable
AI helpers save time, but they rarely output code in your exact Blade/Livewire flavor without heavy prompting and refactoring, especially if your stack uses a lot of componentization.
Summary:
You’re not alone! Even with the best prompts, custom Blade components and strict UI frameworks outpace AI’s “generic Laravel” code. The best approach is to give very concrete code samples, demand compliance, and never hesitate to ask for partial rewrites (“fix the action buttons to use x-button.edit only”). For now—some tweaking is inevitable, but you can minimize it by supplying as much literal example code as possible.
Let me know if you want a simple template to copy from for future CRUDs!