Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»VS Code Snippets for Livewire and Alpine.js

    VS Code Snippets for Livewire and Alpine.js

    July 27, 2024

    VS Code – as many code editors do – includes a feature called “snippets”. The feature allows you to configure shortcuts for pieces of code that you use often. For example, you could set up a snippet so that you type a few characters like fun, press tab, and it’ll expand into a whole function declaration.

    I’ve recently been making another round at optimizing my VS Code setup, so I skimmed through Caleb Porzio’s Make VS Code Awesome course again. It reminded me how useful and powerful these snippets can be, so I started thinking about new ones I could add that would make my life easier. Today, I’ll share some of those with you and maybe you can take a few away that will be useful to your workflow. Specifically, I’ll be sharing ones I use when developing Livewire and Alpine.js apps.

    How to configure snippets in VS Code

    To start off, how do you configure snippets in VS Code? If you already know how, you can skip this section and get to the good part.

    First, open the Command Pallette by pressing cmd+shift+p on Mac or ctrl+shift+p on Windows. Start typing in “Snippets” and it should filter down to an option called “Snippets: Configure User Snippets”. Select that option, then it will prompt you to select the language you want to configure snippets for.

    Following the basic example I mentioned earlier, if you select “javascript.json (JavaScript)” and paste the following snippet inside, you should have successfully configured a “function” snippet that’ll be available when you’re writing in a JS file.

    {
    “Function”: {
    “prefix”: “fun”,
    “body”: [
    “function $1($2) {“,
    ” $3″,
    “}”
    ]
    },
    }

    The configuration of snippets is relatively simple. Each snippet is a JSON object. The key of the object is the snippet name. The prefix inside is the shortcut you’ll use to insert the snippet into your code. The body is an array of lines that will be inserted as part of the snippet. You can also include placeholders in the snippet by using $1, $2, $3, etc. After you insert the snippet, you can continue pressing tab and it’ll move your cursor to each of the placeholders. In this example, the placeholders make it really easy to add the function name, parameters, then body.

    PHP/Livewire

    Now that you know how to configure a snippet let’s go over some of my favorites for PHP and Livewire classes. These can be configured by selecting “php.json (PHP)” in the Command Pallette.

    Class properties and methods cover the basics, but I recent added snippets for Livewire’s mount method, #[Computed] properties (including the PHP attribute), and #[Url] properties.

    {
    “Public Property”: {
    “prefix”: “pub”,
    “body”: [
    “public ${0};”
    ],
    “description”: “PHP Public Property”
    },
    “Computed Property”: {
    “prefix”: “comp”,
    “body”: [
    “#[Computed]”,
    “public function $1()”,
    “{“,
    ” $2″,
    “}”
    ]
    },
    “Livewire Url Property”: {
    “prefix”: “url”,
    “body”: [
    “#[Url$3]”,
    “public $1 = $2;”,
    ]
    },
    “Livewire Mount Method”: {
    “prefix”: “mount”,
    “body”: [
    “public function mount()”,
    “{“,
    ” $1″,
    “}”
    ]
    },
    “Method”: {
    “prefix”: “met”,
    “body”: [
    “public function $1($2)”,
    “{“,
    ” $3″,
    “}”
    ]
    },
    “Private Method”: {
    “prefix”: “pmet”,
    “body”: [
    “private function ${1}(${2})”,
    “{“,
    ” ${0}”,
    “}”
    ],
    “description”: “PHP private function”
    },
    }

    Blade and Alpine.js

    Some of my favorites for Blade and Alpine snippets are:

    con for console.log

    raw for console.log with the value wrapped in Alpine.raw (a tip I covered in a recent article)

    tailwindcdn for the Tailwind CDN script which is useful for quickly setting up Tailwind for demos and testing ideas out

    These can be configured by selecting “blade.json (Blade)” in the Command Pallette.

    {
    “Console Log”: {
    “prefix”: “con”,
    “body”: [
    “console.log($1)”
    ]
    },
    “Console Log (Alpine.raw)”: {
    “prefix”: “raw”,
    “body”: [
    “console.log(Alpine.raw($1))”
    ]
    },
    “Tailwind Play CDN”: {
    “prefix”: “tailwindcdn”,
    “body”: [
    “<script src=”https://cdn.tailwindcss.com”></script>”
    ]
    },
    }

    If you’re using Livewire Volt’s class API, you might find it useful to include you normal PHP snippets in the Blade configuration as well.

    I hope you were able to find some of the snippets useful or at least got some inspiration for snippets that will benefit your own workflow! Again, if you haven’t checked out Caleb’s Make VS Code Awesome course yet, I highly recommend it. It includes a bunch of other snippets that I didn’t cover here, plus theming, keyboard shortcuts, extensions, and more.

    The post VS Code Snippets for Livewire and Alpine.js appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleA guide to Laravel’s model events
    Next Article API Versioning in Laravel 11

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47916 – Invision Community Themeeditor Remote Code Execution

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Insights about GitHub Copilot

    Development

    CVE-2025-30665 – Zoom Workplace Apps for Windows NULL Pointer Denial of Service

    Common Vulnerabilities and Exposures (CVEs)

    Ex-CIA Analyst Pleads Guilty to Sharing Top-Secret Data with Unauthorized Parties

    Development

    Improving MongoDB Queries by Simplifying Boolean Expressions

    Databases

    Highlights

    Top 10 Wastewater Management Solutions by Category

    May 1, 2025

    Post Content Source: Read More 

    CVE-2025-3837 – “VMware End of Life OVA Connect Remote Code Execution Vulnerability”

    April 21, 2025

    Microsoft made Chrome’s incognito more private on Windows 11, Windows 10

    February 6, 2025

    CVE-2025-40616 – Bookgy Reflected XSS

    April 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.