YouTubevideo· May 14, 2024· 9:30
so I often get asked the question what's the best way to learn larabel if you're coming from the JavaScript world in the past my answer has been pretty simple you use inertia JS which is basically allowing you to use react or view or even felt to build with Lille instead of having to write a separate API and then kind of connecting those two pieces together you instead get to serve a view in this case like a view view and just
use that code as you would expect in view or react or spelt but instead it's connecting it to laravel seamlessly you just kind of render that from within your controller this is still very classic in the sense that you're building an MVC framework an MVC application you have a model you have a view and you have a controller and that view is just now powered by react or view or felt but I actually think there's a better way to start learning laril if you're coming
from the JavaScript world and it's diving all in so here's the steps that I would take if I was starting to learn lville as a JavaScript developer the first thing that a lot of people get hung up on is how do I actually set up my development environment and we have an easy answer now with Lille herd and this is for Mac OS and for Windows and basically after you install this you have everything that you need to build a Lille application out the
gates you don't have to worry about things like how do I set up my PHP runtime even things like node all of that is handled within Mac OS so now you don't have to worry about brew and installing PHP and if you have composer installed it's super simple okay so this is my LEL herd application once you install it you can click on sites and settings you can click on this plus button you can create a new larel application right from within laravel
herd now it also installs the CLI so you could do you know laravel new and have that be scaffolded out for you like that if you prefer the CLI but otherwise you can go ahead and just start with one of the starter kits so with this case this is what I would do and again recommend larel Breeze and I would say let's just say JS toille and the Bree stack is going to be
Livewire volt functional API my personal favorite is class but if I was a new JavaScript developer who's built in the JavaScript language for a couple of years now the volt functional API with alpine is going to be what I would say feels most natural let's just go ahead and do this after you've scaffolded out an application within Lille herd then Lille herd builds in the stuff to have development sites in your browser so you
don't have to worry about running anything you can just open this in the browser and it's ready to go there we go this is JS Lille Lille Breeze automatically gives you this off functionality right out the gate so why don't we open this up in our code and see what it looks like and why I think it's a perfect use case for JavaScript Developers just go ahead and say npm run Dev just so we have a development environment ready and again this installed tailwind and installed Aline
and then Live Wire already for us so we have Tailwind right out the gate so if I just open this my vs code now there's so much going on usually within a larl application Lille 11 Slims that down a little bit more but here's how I would start learning larl and more specifically larl Livewire as a JavaScript developer I would go into
routes this is web.php in the routes file and I would go ahead and say hey here's a welcome view now you already have authentication out the gate so if you wanted to leave that authentication baked in which gives you login register like new pages everything like that an authenticated user can visit the dashboard and be ready to go now here's
what I would do just to get started create one single page larel Livewire volt component and then have that page use all the code that you want basically you can write a full larel Livewire application within one file here's how it would look so if you open up your terminal go PHP artisan make volt we'll just
say dashboard perfect dashboard. blade. PHP now in this dashboard component what we'll do is we'll just go ahead and remove this and we'll say Livewire dashboard now we are ready to go here's the awesome thing anything that we write now in our Livewire
dashboard blade. PHP is automatically rendered in our authenticated Dash Point so if you were building an app that you wanted to have users who could register and you know create logins like that and use the power of LEL for authentication now you just write all of this in this one file I I'll show you what this looks like so I was to say um hello from the Live Wire volt
component let's go ahead and look at what this looks like in the browser hello from the Live Wire volt component again we have all the functionality that we don't even have to touch if we don't want to so anything in here since this is a blade component what that means is you can write h t m just like how you normally would so if I was to write an H1 um I was to call it uh let's just say hi there let's write some Tailwind as
well class um we'll say text red and uh we just we'll just do that is it not text red text red 500 we just do that there we go all of this is built into the box whenever you scaffold out a live wire component now here's the kicker here's why I would recommend the functional component style within Larryville Livewire you have the ability
to basically have this more simplistic case where you have things like State can be defined like this where you could call functions without having to actually declare the function and all of this is just done within this one simple file so if I wanted to copy and paste this and actually put this into the component that we just wrote that is what it would
look like there we go if I was to go back into the browser now I have this component that just simply works now the great part about using Lille Livewire volt components is anything in here is just PHP now this is probably the most confusing thing as a JavaScript developer because you're like I don't know PHP but this gives you a great playground to start learning so if you
wanted to actually um do anything within lay let's say you wanted to call a uh a mailable which means I want to send email within a Livewire Vol component you can do that if you want to add something to a queue within larel you can do that all within this one function all within this one Livewire volt code block now the reason
why I say just start playing around with this specifically is because this gives you the ability to kind of build from there so instead of maybe you you don't want all of your logic in one block like you might want that's good to separate things out then you can start getting into okay when do I separate this into a component then you can learn the resources for that okay when do I you know start building out a job or a CU then you can learn the resources for
that but everything that you might want to do in a more JavaScript way if you want to think of it that can be done within this Live Wire VT component so again this is this is isn't necessarily teaching you how to write Live Wire how to write V that can be coming in in later videos but this is just say if you wanted to get started I would look up the Live Wire documentation for anything
this volt page specifically so if you want to say okay how do I within Live Wire volt let's say start doing it like any pagination or if I wanted to call something on Mount and this case that would be like a a use effect for example when the component is actually mounted having this one playground already set up for you allows you to
dive into the aspects of lell aspects of Livewire that are intriguing because then if you go to because then if you go to lal.com and you're like okay how do I specifically you know start querying the database then you can do that all within laravel volt now all a sudden you have this
functionality to kind of add PHP and learn PHP as you're building this out without having to dive into the weeds of where do I specifically put this code so hopefully this helps but more importantly hopefully helps gives you a starting point to learn to Kickstart your learning and build some cool things with larvo live wire with volt and with PHP