search results:

    • Standard
    • React
    Pricing Learn Community
    • + D
    • Light
    • Dark
    • System
    logo TW Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Migrating to v2
      • Internationalization guide
      • Class customization
      • Icons Integration
    • CommercialNew
      • Pricing
      • License
      • Installation
      • Git & repository
      • Premium Support
    • Integrations
      • Angular
      • ASP.NET
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • Qwik
      • React
      • Remix
      • Solid
      • Svelte
      • SvelteKit
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Autocomplete
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Multi range slider
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Admin Charts
      • Admin Complex
      • Admin Forms
      • Admin Maps
      • Admin Navigation
      • Admin tables
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Stats admin
      • Team
      • Testimonials
    • Tools
      • Button generator
      • Card generator
      • Flexbox generator
      • Footer generator
      • Form builder
      • Grid generator
      • Icon generator
      • Instagram Filters generator
      • Logo generator
      • Table generator
      • Typography generator
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • Resources
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips

    TW Elements Laravel integration

    This article shows you how to integrate Laravel application with TW Elements. Free download, open source license.


    Prerequisites

    Before starting the project make sure to install the following utilities:

    • Node LTS (18.x.x or higher recommended)
    • PHP
    • Composer
    • Code editor. We recommend VSCode

    Creating a new Laravel application

    Let's create a fresh Laravel application so that we can go through all the steps together.

    Note: If you have trouble with installing composer and you got an error bound installation - try composer install --ignore-platform-req=ext-fileinfo or composer update --ignore-platform-reqs.

    Step 1

    Create new project.

    • Terminal
            
                
        composer create-project laravel/laravel my-project
        cd my-project
        
            
        

    Step 2

    Run the development server.

    • Terminal
            
                
        php artisan serve
        
            
        

    Installing and configuring Tailwind CSS and TW Elements

    Step 1

    Install Tailwind CSS.

    • Terminal
            
                
        npm install -D tailwindcss postcss autoprefixer
        npx tailwindcss init -p
        
            
        

    File structure

    If you have followed all instructions mentioned earlier, your file structure should look like this:

          
            my-project/
            ├── ...
            ├── node_modules/       
            ├── public/  
            ├── resources/
            │   ├── css/
            │   │   └── app.css
            │   ├── js/
            │   │   ├── app.js
            │   │   └── ...
            │   └── views/
            │       └── welcome.blade.php
            ├── ...
            ├── package-lock.json
            ├── package.json
            ├── ...
            ├── postcss.config.js
            ├── README.md
            ├── tailwind.config.js
            └── vite.config.js
          
        

    Step 2

    Add the paths to all of your template files in your tailwind.config.js file.

    • tailwind.config.js
            
                
        /** @type {import('tailwindcss').Config} */
        module.exports = {
          content: [
            "./resources/**/*.blade.php",
             "./resources/**/*.js",
            "./resources/**/*.vue",
            "./node_modules/tw-elements/js/**/*.js"
          ],
          theme: {
            extend: {},
          },
          darkMode: "class",
          plugins: [require("tw-elements/plugin.cjs")]
        }
        
            
        

    Step 3

    Add the @tailwind directives for each of Tailwind’s layers to your app.css file.

    • ./resources/css/app.css
            
                
        @import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900&display=swap");
        @tailwind base;
        
        @layer base {
          html {
            @apply text-surface;
            @apply bg-white;
          }
          html.dark {
            @apply text-neutral-50;
            @apply bg-body-dark;
          }
        }
        
        @tailwind components;
        @tailwind utilities;
        
        p {
          @apply leading-[1.6];
        }    
        
            
        

    Step 4

    Make sure your compiled CSS and JS are included in the head in welcome.blade.php file.

    • ./resources/views/welcome.blade.php
            
                
        @vite('resources/css/app.css')
        @vite('resources/js/app.js')
        
            
        

    Step 5

    Install TW Elements.

    • Terminal
            
                
        npm install tw-elements
        
            
        

    Step 6

    Import and initialize with initTWE function components which are you intend to use and necessary function initTWE in app.js. Additionally add HTML markup for components in the welcome.blade.php file.

    • ./resources/js/app.js
    • ./resources/views/welcome.blade.php
            
                
        import { Tooltip, initTWE } from "tw-elements";
        initTWE({ Tooltip });
        
            
        
            
                
        ...
        <main>
          <div class="mt-16 flex justify-center">
            <p class="text-lg">
              Hover the link to see the
              <a
                href="#"
                class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
                data-twe-toggle="tooltip"
                title="Hi! I'm tooltip"
                >tooltip</a
              >
            </p>
          </div>
        </main>
        ...
        
            
        

    Step 7

    Start build process.

    • Terminal
            
                
        npm run dev
        
            
        

    And run the development server. Awesome! You're all set to dive into using TW Elements for your Laravel project. Have fun!

    • Terminal
            
                
        php artisan serve
        
            
        

    Initializing via JS

    By default all components have autoinit which means they are initialized by data attributes. But if you want to make init by JavaScript - there is also possibility to do that.

    Step 1

    Import and initialize components.

    • ./resources/js/app.js
    • ./resources/views/welcome.blade.php
            
                
        import { Tooltip } from 'tw-elements';
    
        const myTooltip = new Tooltip(document.getElementById('my-tooltip'));
        
            
        
            
                
        ...
        <main>
          <div class="mt-16 flex justify-center">
            <p class="text-lg">
              Hover the link to see the
              <a
                id="my-tooltip"
                href="#"
                class="text-primary transition duration-150 ease-in-out hover:text-primary-600 focus:text-primary-600 active:text-primary-700 dark:text-primary-400 dark:hover:text-primary-500 dark:focus:text-primary-500 dark:active:text-primary-600"
                title="Hi! I'm tooltip"
                >tooltip</a
              >
            </p>
          </div>
        </main>
        ...
        
            
        

    Troubleshooting

    Problem overview:

    After initializing TWE components as described in the documentation you can got erros like (TWE Components name) is not defined or te is not defined.

    Suggested solution:

    Set variables or constants to the window scope.

    • Code
            
                
              const { Tooltip, initTWE } = await import("tw-elements");
    
              window.iniTWE = initTWE;
              window.Tooltip = Tooltip;
    
              initTWE({ Tooltip });
              
            
        

    Source GitHub Discussion #1839 #1737


    Related resources

    Tutorials:

    introduction key concepts quick start vite mdb go and deploy create website about versions installation setup overview create landing page javascript tailwind css intellisense deploy repository

    Integrations :

    angular django express next nuxt react remix solid svelte sveltekit vue
    • Prerequisites
    • Creating a new Laravel application
    • Installing and configuring Tailwind CSS and TW Elements
    • Initializing via JS
    • Troubleshooting
    • Related resources
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2024 Copyright: MDBootstrap.com

    Access restricted

    To view this section you must have an active PRO account

    Log in to your account or purchase an TWE subscription if you don't have one.

    Buy TWE PRO