Alpine.js Example in Laravel: Master-Detail Form
Chapters7
Introduces AlpineJS as a lightweight option for adding small dynamic behaviors in Blade without learning React or Vue, often used with LiveWire.
Alpine.js can power dynamic forms in Laravel Blade without Livewire, demonstrated with a master-detail recipe form and in-page Alpine data and methods.
Summary
Laravel Daily’s video shows how to use Alpine.js inside a plain Blade page without Livewire, highlighting a real-world master-detail form (recipes with ingredients and steps). Claude Code’s example sits inside a regular Laravel controller and blade, not a Livewire component, proving Alpine.js can drive dynamic UI locally while the server handles the final submit. Caleb Porzio’s Alpine ecosystem is presented as a lightweight alternative to heavier frameworks, ideal for small, interactive tweaks in a Blade-heavy project. The presenter walks through defining Alpine data with x-data, then using x-model for inputs and click handlers for add/remove logic, all within a single div or form. He contrasts this with Livewire’s server-side state updates, showing how Alpine maintains state locally until submission. The video also points out that you can mix Alpine with the Laravel Livewire starter kit, using plain controllers and blades without wired Livewire markup. Finally, the talk encourages exploring Alpine’s docs and even mentions a beginner course from Laravel Daily for those who want a structured path. If you’re wary of React/Vue in Laravel, this is a practical, concrete demonstration of how to implement dynamic forms with minimal JavaScript."
Key Takeaways
- Alpine.js can be used in a standard Laravel Blade form without Livewire, keeping UI logic on the client side.
- The example defines two main Alpine data objects (ingredients and instructions) and corresponding add/remove methods to manage them locally.
- x-model and x-data enable in-page reactivity, demonstrated by dynamic ingredient rows and instruction steps.
- Submitting the form sends a regular Laravel request, with all Alpine-managed state resolved prior to server-side processing.
- You can still use the Livewire Starter Kit alongside Alpine by keeping the Blade page separate from Livewire components.
- The presenter notes that Alpine.js keeps dependencies small and avoids the complexity of React/Vue for simple dynamic behaviors.
- The video mentions a legacy Alpine course on Laravel Daily for those who prefer a guided, structured learning path.
Who Is This For?
Essential viewing for Laravel developers who want dynamic behavior in Blade without learning React or Vue, and for teams using the Livewire Starter Kit but needing standalone Alpine.js pages.
Notable Quotes
"Alpine.js is exactly for that case."
—Introduce Alpine.js as a lightweight option for small dynamic things in Laravel without React or Vue.
"if you have a regular Laravel project with blade without react without Vue.js and you don't want to learn them but you still want to have some JavaScript with some very small dynamic things on the website. AlpineJS is exactly for that case."
—Explains the motivation for using Alpine.js over heavier frameworks.
"you can create regular blade page and then add X data with AlpineJS inside and you can learn more about AlpineJS of course on its official website."
—Points to how to get started with Alpine.js and where to learn more.
Questions This Video Answers
- How can I implement a master-detail form in Laravel Blade using Alpine.js without Livewire?
- What is the difference between Alpine.js state management (x-data) and Livewire's server-side state updates?
- Can I mix Alpine.js with the Laravel Livewire Starter Kit and when would I do that?
- What are practical Alpine.js patterns for dynamic form fields like ingredients and steps?
- Where can I learn Alpine.js basics for Laravel in a concise course?
AlpineJSLaravel BladeLivewire Starter KitX-DataX-ModelLaravel controllers vs. LivewireMaster-detail formsJavaScript minimalism
Full Transcript
Hello guys, today in this video I want to show you an example reminding you of some text tack choice that is really underrated in Laravel community and in general in JavaScript world which is AlpineJS and usually Alpine.js GS is tied together with LiveWire because it comes from the same author Caleb Porzio and in a typical composer JSON of Laravel project with LiveWire starter kit you may find this which means that some Alpine is already under the hood but recently I had a case which I want to show you where AI agent cloud code generated this complex form for me with AlpineJS without live wire.
So this is an example how you can use typical blade form with alpine on top for some dynamic behavior which means if you have a regular Laravel project with blade without react without Vue.js and you don't want to learn them but you still want to have some JavaScript with some very small dynamic things on the website. AlpineJS is exactly for that case. So here's a form to add recipe. This is zoomed in version. Let's fill something in with fake filrom extension. Some tags, some ingredients. And then I can add ingredient. So this is AlpineJS. So we add something something quantity.
This is probably too much zoomed in because drop-downs are on one another. Then similar thing add step. So this is Alpine.js as well. And for example, if we save that, this is the page to view that recipe. And then in the edit form you can choose more or less ingredients. So for example we can delete the ingredient and for now it's deleted only with JavaScript. The submission of the form only then saves the data update the recipe and then we have only one ingredient. This is live wire starter kit. If you do something like that with live wire for example add step and then you add new item to the array of livewire instructions it will call server side.
This is how livewire works. If you do that with alpine you're working with local JavaScript array of instructions and only then after I submit all the form it gets submitted to the server. So basically you're working locally with JavaScript which is exactly the point of such dynamic form. So let me show you the code of that page. This project itself is live wire starter kit but this specific page is recipe controller regular controller in routes web. We have route resource and this is kind of a side note you can use livewire starter kit but inside of that you can do laravel controllers without any livewire.
This is one of the reasons why there's no blade starter kit in Laravel 12. Livewire starter kit is considered to be that thing. So yeah, we have a controller with create and then edit forms with route model binding here as you can see. So there is no live wire here. And if we go to that edit blade, it uses the same layouts app from livewire starter kit. But inside of that file, you cannot find any wire something. So it's not live wire, it's just alpine. And where do we see that Alpine here? First, we see some PHP operations to have the collection map through recipe ingredients and recipe instructions.
To be honest, I would probably move that to the controller method in the edit form. As I said, this code is not mine. It's written by Claude Code fully for one of the experiments. So, I sometimes feel in the shoes of code reviewer like I used to do more often on this channel, but I was reviewing junior code. Now, quite often I review AI written code, which is quite good actually. But we have to pay attention to the details. But unexpectedly I didn't ask for that cloud code generated alpine here like this. So we have a regular form with action route.
This is not a dynamic form. So no react or Vue.js or LiveWire. But inside we have local variables. This is how you define data in AlpineJS. So we have ingredients instructions and then methods for add or remove something. And those methods work with local this instructions and this ingredients. Then also move instructions. So basically these two local variables are the main things in that Alpine.js component. So it's basically whenever you have X data everything inside of that is considered Alpine.js component. And then if we scroll down to ingredients for example flux button it does use flux components the starter the free version of flux but here we find this at click add ingredient and that add ingredient is the function defined earlier as you saw in AlpineJS component.
So basically if you haven't seen AlpineJS in action before it's not using separate components it's all kind of in line of the same div or form in this case and the methods are defined on top and then everywhere inside of that form we can use those methods like this or perform some AlpineJS inline operations like this for example. So this is AlpineJS code for loop for ingredient we show X model ingredient name then X model ingredient quantity and so on. So the main idea and benefit of AlpineJS in my opinion is it feels similar to React or Vue with syntaxes like this where you define the variable and the modeling but it doesn't require extra components thinking about the structure.
It's all inside the same blade. So you saw the loop of ingredients and then also at the bottom we have button with add click remove ingredient which is another method inside of the same alpine component and same down below with instructions template for instruction index and then pretty similar code and at the end of that whole page we have just form and there's no JavaScript here at the bottom or on top the same inputs which you dynamically work with AlpineJS the same inputs are provided as form confirm data in a regular Laravel action to update method of recipe controller.
Here's that method which then performs the update with just regular request and validated data. So yeah, this is what I want to emphasize and show AlpineJS in action with the idea that you can use it outside of LiveWire. You can install it separately without livewire or if you're using livewire starter kit which contains Alpine you can create regular blade page and then add X data with AlpineJS inside and you can learn more about AlpineJS of course on its official website. So this is a very simple example like hello world counter. So you define X data with well data and then inside you do X whatever with Alpine.
So this actually works. And then in the docs we have more directives and more things you need to learn. Or you may prefer my way of teaching. I have a course on AlpineJS on Laraveville daily. Actually very old course from 2022. But at the same time Alpine didn't change since then. If you find in the course any details that are actually changed, please report in the comments. But from my understanding, AlpineJS is pretty stable for basically many years because it's a small library just for these types of operations. So if you prefer my way of teaching in video in 1 hour, I will link that course in the description below.
What do you think about AlpineJS? Are you using it in your projects or what maybe are the reasons why you're not using that? Let's discuss all of that in the comments below. That's it for this time and see you guys in other
More from Laravel Daily
Get daily recaps from
Laravel Daily
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.







