Thank you! :) I am working on it. I have one coming out on Laracasts and then I'm working on updating my Livewire TALL stack course here on UA-cam with a Livewire crash course. ☺️
first time i saw that you can dispatch events from js to php and from php to js i was blown away, and then i learned that u can just push js from your php and i was even more blown away
Great video. I don’t know that the PHP function returning JS would run client side. I still thought it would do a server request 😮 good to know! Great video as always man 👏
I didn't know about this until a few weeks ago! It's neat that it can just compile to AlpineJS on build time (I need to make a video on how it works!) but thank you for the support. ☺️ (this material is gonna be solid for my Livewire crash course. 😮💨)
As someone that really likes JS, I don't mind using it. But it is nice being able to use PHP run JS functions. Definitely would have been nice to have had in my last project.
I like using AlpineJS myself and often abstract it to a script tag for data when needed, but it IS nice to have those one off JavaScript commands for use every now and then. 😁
except that you are NOT "running javascript in php", all you are doing is scaffolding a js statement and passing it to the view. Identical to just putting it in the view.
I use this to create couple of helper methods in my Livewire components like the one to refresh the whole page and with $delay support. public function refreshPage(int $delay = 0): void { $this->js(sprintf('setTimeout(function() { window.location.reload(); }, %d);', $delay)); }
I did not know this when my tailwind toggle switches were not updating realtime, so ended up using dispatch and wire.on functions on the client side to reset the switches which was a pain
And there's some helpful features for something like a toggle switch too where you can @entangle the component so that way it switches client side and THEN switches it server side too! :)
My first thought upon seeing the thumbnail and the title of this video and the only reason why I clicked on it: Why Seth Rogen talks about PHP and JavaScript?
So idk. Maybe at this point is better to use js instead? I think you have rebuild a js logic. Here why I'm really uncertain on wich stack I have to use.. Cheers
I think this just shows there's multiple ways of writing JS in your Livewire app depending on what you prefer and how you want to use JS syntax. I will probably have a good collection of this and Alpine and this->js() all in one single component. And that's okay. ☺️
As much as I love using Laravel and Adonisjs, I **hate** PHP, they don't even have a basic implementation of an LSP (something that neovim hobbyist can build in weeks)
Hmm. Theres Intelephense, PHPactor, and a few other hobbyist built ones. Where did you get the idea that PHP doesn’t have an LSP? I’ve been using one in every IDE that I’ve used with Laravel/PHP.
@@joshcirre It does have an LSP, a very bad one, tho. Folks using PHPStorm are enjoying the good version of it (IDK who made the PHPStorm LSP, but it's better than the free one).
@joshcirre Hey, I found a way to handle hiding the modal after it's created! I've added this to the Livewire class function save() $this->dispatch('permission-created'); And in the Livewire Blade view, I added this: @section('scripts') document.addEventListener('livewire:init', () => { Livewire.on('permission-created', () => { const modal = bootstrap.Modal.getInstance(document.getElementById('kt_modal_add_permission')); if (modal) { modal.hide(); } }); }); @endsection
I don't know about this one man. We spent a good effort fighting JavaScript's transition to the server, but I think we should let it do it's thing freely on the client. else we're just as guilty as the react/next.js people, the php way.
It is doing it's thing freely on the client. It's just a different way of writing it that sticks with APIs and styles you might already be using in your Livewire component. So, like I showed, I don't think it's any different than if you wanted to write that out in Alpine instead (or JQuery for example since the $wire object is exposed to the client). Just a different way of doing it. But, in the end, it comes down to personal preference. :)
What! I didnt know this was possible. You should create a Laravel course!
Thank you! :) I am working on it. I have one coming out on Laracasts and then I'm working on updating my Livewire TALL stack course here on UA-cam with a Livewire crash course. ☺️
first time i saw that you can dispatch events from js to php and from php to js i was blown away, and then i learned that u can just push js from your php and i was even more blown away
Absolutely crazy right?! It helps that the creator of Livewire made AlpineJS too. There's a lot of "real world" use-cases for every single feature. ☺️
Great video. I don’t know that the PHP function returning JS would run client side. I still thought it would do a server request 😮 good to know!
Great video as always man 👏
I didn't know about this until a few weeks ago! It's neat that it can just compile to AlpineJS on build time (I need to make a video on how it works!) but thank you for the support. ☺️
(this material is gonna be solid for my Livewire crash course. 😮💨)
As someone that really likes JS, I don't mind using it. But it is nice being able to use PHP run JS functions. Definitely would have been nice to have had in my last project.
I like using AlpineJS myself and often abstract it to a script tag for data when needed, but it IS nice to have those one off JavaScript commands for use every now and then. 😁
except that you are NOT "running javascript in php", all you are doing is scaffolding a js statement and passing it to the view. Identical to just putting it in the view.
Thanks! I use custom Filamentphp Form and Action a lot and I see this can be really helpful at some places.
I think Filament v4 is going to have a lot of great helpers to run Alpine code from your Filament code, as well! :)
I use this to create couple of helper methods in my Livewire components like the one to refresh the whole page and with $delay support.
public function refreshPage(int $delay = 0): void
{
$this->js(sprintf('setTimeout(function() { window.location.reload(); }, %d);', $delay));
}
Oooo. Very nice. I'll have to add that to my notes. I like it.
Really help full, thank you for your efforts 🎉❤
Thanks for the support. I'm glad it can be useful. ☺️
JOSH! What are you using to fold up the Tailwind classes into those logos?!?!?! That's awesome!
Tailwind Fold... found it, so nice!
You found it! Sorry I replied so late. It's been nice for these types of videos. ☺️
Alpine is fantastic, Josh!
It really is. I just wrapped up recording for a Laracasts course where I did a TON of Alpine... and I loved it. :)
I did not know this when my tailwind toggle switches were not updating realtime, so ended up using dispatch and wire.on functions on the client side to reset the switches which was a pain
And there's some helpful features for something like a toggle switch too where you can @entangle the component so that way it switches client side and THEN switches it server side too! :)
My first thought upon seeing the thumbnail and the title of this video and the only reason why I clicked on it: Why Seth Rogen talks about PHP and JavaScript?
I really need to capitalize on this. I get this once a week. 😂
Can you make a video about rich text editors in laravel and livewire?
Sure! I'll add it to the list here: cir.re/suggest
I personally think Filament has a great out of the box option for Livewire. 😁
@@joshcirre agree!
So idk. Maybe at this point is better to use js instead? I think you have rebuild a js logic. Here why I'm really uncertain on wich stack I have to use.. Cheers
I think this just shows there's multiple ways of writing JS in your Livewire app depending on what you prefer and how you want to use JS syntax. I will probably have a good collection of this and Alpine and this->js() all in one single component. And that's okay. ☺️
@@joshcirre thank you for clarification. I missed the whole point of your video xD best regards and keep Rollin! 🤘
Can we send you the full json file?
As much as I love using Laravel and Adonisjs, I **hate** PHP, they don't even have a basic implementation of an LSP (something that neovim hobbyist can build in weeks)
Hmm. Theres Intelephense, PHPactor, and a few other hobbyist built ones.
Where did you get the idea that PHP doesn’t have an LSP? I’ve been using one in every IDE that I’ve used with Laravel/PHP.
@@joshcirre It does have an LSP, a very bad one, tho. Folks using PHPStorm are enjoying the good version of it (IDK who made the PHPStorm LSP, but it's better than the free one).
Really usefull thanks
Glad it could be useful! ☺️
How to dispatch modal window in livewire 3 after submit form ? would you please make a viode for it ?
I'll add it to the list! :)
(cir.re/suggest)
@@joshcirre thank you ♥, It would be nice if you use bootstrap not tailwind.
any How thank for adding this to the list ♥♥
@joshcirre Hey, I found a way to handle hiding the modal after it's created!
I've added this to the Livewire class function save()
$this->dispatch('permission-created');
And in the Livewire Blade view, I added this:
@section('scripts')
document.addEventListener('livewire:init', () => {
Livewire.on('permission-created', () => {
const modal = bootstrap.Modal.getInstance(document.getElementById('kt_modal_add_permission'));
if (modal) {
modal.hide();
}
});
});
@endsection
I don't know about this one man.
We spent a good effort fighting JavaScript's transition to the server, but I think we should let it do it's thing freely on the client.
else we're just as guilty as the react/next.js people, the php way.
It is doing it's thing freely on the client. It's just a different way of writing it that sticks with APIs and styles you might already be using in your Livewire component.
So, like I showed, I don't think it's any different than if you wanted to write that out in Alpine instead (or JQuery for example since the $wire object is exposed to the client). Just a different way of doing it.
But, in the end, it comes down to personal preference. :)
Awesome. Is there any same helper in laravel controller ?
Nope! Just because this compiles to Alpine code under the hood. So only for Livewire, unfortunately. :)
😊👍🏻👍🏻
Thanks for watching! ☺️
.