Writing JavaScript in PHP?!

Поділитися
Вставка
  • Опубліковано 7 вер 2024

КОМЕНТАРІ • 47

  • @pythonantole9892
    @pythonantole9892 Місяць тому +4

    What! I didnt know this was possible. You should create a Laravel course!

    • @joshcirre
      @joshcirre  Місяць тому +3

      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. ☺️

  • @OS-Advertising
    @OS-Advertising Місяць тому

    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

    • @joshcirre
      @joshcirre  Місяць тому

      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. ☺️

  • @Devdojo
    @Devdojo Місяць тому

    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 👏

    • @joshcirre
      @joshcirre  Місяць тому

      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. 😮‍💨)

  • @thedude6810
    @thedude6810 Місяць тому +1

    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.

    • @joshcirre
      @joshcirre  Місяць тому

      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. 😁

    • @MarkSnape
      @MarkSnape Місяць тому

      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.

  • @fathularifkamarudin55
    @fathularifkamarudin55 Місяць тому

    Thanks! I use custom Filamentphp Form and Action a lot and I see this can be really helpful at some places.

    • @joshcirre
      @joshcirre  Місяць тому

      I think Filament v4 is going to have a lot of great helpers to run Alpine code from your Filament code, as well! :)

  • @devhammed
    @devhammed Місяць тому +1

    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));
    }

    • @joshcirre
      @joshcirre  Місяць тому +1

      Oooo. Very nice. I'll have to add that to my notes. I like it.

  • @development2301
    @development2301 Місяць тому

    Really help full, thank you for your efforts 🎉❤

    • @joshcirre
      @joshcirre  Місяць тому +1

      Thanks for the support. I'm glad it can be useful. ☺️

  • @fylzero
    @fylzero Місяць тому

    JOSH! What are you using to fold up the Tailwind classes into those logos?!?!?! That's awesome!

    • @fylzero
      @fylzero Місяць тому

      Tailwind Fold... found it, so nice!

    • @joshcirre
      @joshcirre  Місяць тому +1

      You found it! Sorry I replied so late. It's been nice for these types of videos. ☺️

  • @alinuxist
    @alinuxist Місяць тому

    Alpine is fantastic, Josh!

    • @joshcirre
      @joshcirre  Місяць тому

      It really is. I just wrapped up recording for a Laracasts course where I did a TON of Alpine... and I loved it. :)

  • @devOnHoliday
    @devOnHoliday Місяць тому

    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

    • @joshcirre
      @joshcirre  Місяць тому

      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! :)

  • @Dziekan765
    @Dziekan765 Місяць тому +1

    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?

    • @joshcirre
      @joshcirre  Місяць тому

      I really need to capitalize on this. I get this once a week. 😂

  • @alinuxist
    @alinuxist Місяць тому

    Can you make a video about rich text editors in laravel and livewire?

    • @joshcirre
      @joshcirre  Місяць тому

      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. 😁

    • @alinuxist
      @alinuxist Місяць тому

      @@joshcirre agree!

  • @user-ek8hs5bg2y
    @user-ek8hs5bg2y Місяць тому

    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

    • @joshcirre
      @joshcirre  Місяць тому

      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. ☺️

    • @user-ek8hs5bg2y
      @user-ek8hs5bg2y Місяць тому

      @@joshcirre thank you for clarification. I missed the whole point of your video xD best regards and keep Rollin! 🤘

  • @davidgrigoryana
    @davidgrigoryana Місяць тому

    Can we send you the full json file?

  • @skeletala
    @skeletala Місяць тому

    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)

    • @joshcirre
      @joshcirre  Місяць тому

      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.

    • @skeletala
      @skeletala Місяць тому

      @@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).

  • @delreda
    @delreda Місяць тому

    Really usefull thanks

    • @joshcirre
      @joshcirre  Місяць тому

      Glad it could be useful! ☺️

  • @yacoublearn
    @yacoublearn Місяць тому

    How to dispatch modal window in livewire 3 after submit form ? would you please make a viode for it ?

    • @joshcirre
      @joshcirre  Місяць тому

      I'll add it to the list! :)
      (cir.re/suggest)

    • @yacoublearn
      @yacoublearn Місяць тому

      @@joshcirre thank you ♥, It would be nice if you use bootstrap not tailwind.
      any How thank for adding this to the list ♥♥

    • @yacoublearn
      @yacoublearn Місяць тому

      @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

  • @ajzack983
    @ajzack983 Місяць тому +1

    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.

    • @joshcirre
      @joshcirre  Місяць тому +1

      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. :)

  • @jjplays404
    @jjplays404 Місяць тому

    Awesome. Is there any same helper in laravel controller ?

    • @joshcirre
      @joshcirre  Місяць тому +1

      Nope! Just because this compiles to Alpine code under the hood. So only for Livewire, unfortunately. :)

  • @aimperialdesign6519
    @aimperialdesign6519 Місяць тому

    😊👍🏻👍🏻

    • @joshcirre
      @joshcirre  Місяць тому +1

      Thanks for watching! ☺️

  • @bakasenpaidesu
    @bakasenpaidesu Місяць тому +1

    .