Dynamic Laravel Livewire Bootstrap 5 modals.

Overview

Laravel Livewire Modals

Dynamic Laravel Livewire Bootstrap 5 modals.

Requirements

  • Bootstrap 5

Installation

Require the package:

composer require bastinald/laravel-livewire-modals

Add the livewire:modals component to your app layout view:

<livewire:scripts/>
<livewire:modals/>
<script src="{{ asset('js/app.js') }}"></script>

Require ../../vendor/bastinald/laravel-livewire-modals/js/modals in your app javascript file:

require('@popperjs/core');
require('bootstrap');
require('../../vendor/bastinald/laravel-livewire-modals/js/modals');

Usage

Specify a title for the modal in your Livewire component (the modal body content comes from the render method):

class ProfileUpdate extends Component
{
    public $title = 'Update Profile';

    public function render()
    {
        return view('profile-update');
    }
}

Show the modal via $emit('showModal', 'component-alias'):

<button type="button" 
    wire:click="$emit('showModal', 'profile-update')">
    {{ __('Update Profile') }}
</button>

You can also pass parameters to the component mount method:

<button type="button" 
    wire:click="$emit('showModal', 'user-update', {{ $user->id }})">
    {{ __('Update User: ' . $user->name) }}
</button>

Your component mount method for the example above would look something like this:

public $user;

public function mount(User $user)
{
    $this->user = $user;
}

Hiding the currently open modal can be done via $emit('hideModal'):

<button type="button" wire:click="$emit('hideModal')">
    {{ __('Close') }}
</button>

You can also hide modals inside your Livewire component via $this->emit('hideModal'):

public function save()
{
    $this->validate();

    // save the record

    $this->emit('hideModal');
}
Comments
  • Not working

    Not working

    after many checking the package readme as how can i install and use it into laravel. after installing the package and adding some code into project like with what we see in read me, clicking on button doesn't show any modal

    opened by pishguy 4
  • Maybe add offcanvas here?

    Maybe add offcanvas here?

    Good extension.

    offcanvas has similar functionality. can add it here or make another similar extension.

    also sometimes multimodal is needed. no plans to do?

    opened by rik43 2
  • Autofocus on input within Modal

    Autofocus on input within Modal

    Double checked some of your existing modals and even tried adding autofocus to an input, but no dice. I think there needs to be a way to autofocus on the first input opening a form within a modal. Thoughts? I opened it here because i figured it would apply to this package and your ui package.

    opened by MACscr 2
  • Improvement : url/Routes create, show & edit

    Improvement : url/Routes create, show & edit

    Hello,

    Do you plan to have any implementation of show, create & edit routes ? Today, when we click on "read" or "edit" it's a javascript-button . If we refresh the page, we loose the popup (going back to the main page). Could be useful to:

    • when we click, the url is changing (History.pushState())
    • when we refresh the page (or we point directly to /model/3/read), the corresponding modal is opened again

    Right now, I did something like that:

    class Index extends Component
    {
        public $entity;
        public $action;
    
        public function route()
        {
            return Route::get('member/tn-members/{entity?}/{action?}', static::class)
                ->name('member.tn-members')
                ->middleware('auth');
        }
    
        public function loaded() {
            if( $this->entity->exists ) {
                switch($this->action) {
                    case 'show':
                        $this->emit('showModal', 'member.tn-members.read', $this->entity->id);
                        break;
    
                    case 'edit':
                        $this->emit('showModal', 'member.tn-members.save', $this->entity->id);
                        break;
    
                    case 'create':
                        $this->emit('showModal', 'member.tn-members.save');
                        break;
                }
            }
        }
    
        public function mount($entity = null, $action = 'show') {
            $this->entity = TnMember::findOrNew($entity);
            $this->action = $action;
        }
        // [...]
    }
    

    And the view:

    @section('title', __('Tn Members'))
    <div wire:init="loaded">
    
    1. Creating two optional parameters /{entity?}/{action?}
    2. Storing the two parameters
    3. Creating a wire:init + the method associated
    4. Emit showModal depending of the parameters

    (I also tried with addEventListener('contentChanged') but we still need the wire:init)

    Now, when I use the url the modal are automatically opening (like trello cards)

    There is maybe another way to do it :)

    For the other point (History.pushState), it's another story. I don't know if the best is to change a little bit the emit parameters ? pass the route directly ? add extra parameter like data-href ?

    wire:click="$emit('showModal', 'member.tn-members.read', route('member.tn-members', ['entity' => $tnMember->id, 'action' => 'show']), {{ $tnMember->id }})"
    

    or

    <x-bs::button icon="eye" :title="__('Read')" color="outline-primary" size="sm"
      data-href="{{ route('member.tn-members', ['entity' => $tnMember->id, 'action' => 'show']) }}"
      wire:click="$emit('showModal', 'member.tn-members.read', $event.target.getAttribute('data-href'), {{ $tnMember->id }})"/>
    

    or manipulate via Modals::showModal, but need to handle create(=save & no id)/edit(=save & id)/show(=read) or let the Read/Save component handle the route event and raise an $emit('changeUrl') ?

    (Interesting article with potential solution about the changeUrl event: https://github.com/livewire/livewire/issues/399)

    opened by Thiktak 1
  • JS & Crud improvements: protect and singleton

    JS & Crud improvements: protect and singleton

    Hello,

    I use this modal component, and I have some possible improvements:

    modal.js > use getOrCreateInstance instad of new Modal.

    This will prevent to have several overlay displayed (without possibility to clean them), if we have modal with modal link inside or if we want to do some navigation.

    Livewire.on('showBootstrapModal', () => {
        let modal = Modal.getOrCreateInstance(modalsElement);
        if( modal ) {
            modal.show();
        }
    });
    

    modal.js > protect modal.hide

    If we trigger event hideModal, and this one does not exists ... there is an error. Linked to next improvement too.

    Livewire.on('hideModal', () => {
        let modal = Modal.getInstance(modalsElement);
        if( modal ) {
            modal.hide();
        }
    });
    

    Crud: reverse the two emits

    Currently we have $this->emit('$refresh'); $this->emit('hideModal'); but I think it could be better to have:

            $this->emit('$refresh');
            $this->emit('hideModal');
    

    Indeed, this will prevent the system to not refresh (i.e.: the list), if the modal does not exists (i.e.: trigger event via another Component) and/or protect the modal.hide().

    Crud: modal-body

    I created a system to change the modal in "columns", and I had some issues when I tried to play with the layout & css (flex, overflow). To provide more flexibility, could it be possible to separate the modal-body and the content ?

            <div class="modal-body">
                <div class="d-grid gap-3"></div>
            </div>
    

    If everything is on the same tag, the flex propriety of the d-grid is filling all the height of the modal-body, and the inputs are like that : 2021-07-03 18_41_42-Window

    opened by Thiktak 1
  • Dev

    Dev

    LaravelLivewireScripts directive has been added. Users can now use @LaravelLivewireScripts in the App template and it will automatically include JavaScript files

    opened by luanardev 0
  • Support  for bootstrap 4

    Support for bootstrap 4

    Any chance you could add support for bootstrap 4?

    It seems all that needs to change is the javascript that you import:

    // modals-bs4.js
    let modalsElement = document.getElementById('laravel-livewire-modals');
    
    $(modalsElement).on('hidden.bs.modal', () => {
      Livewire.emit('resetModal');
    });
    
    Livewire.on('showBootstrapModal', () => {
      $(modalsElement).modal('show');
    });
    
    Livewire.on('hideModal', () => {
      $(modalsElement).modal('hide');
    });
    

    Thanks, love the package!

    opened by sbrow 4
  • Wire:loading on the trigger element

    Wire:loading on the trigger element

    Some modals can be pretty heavy to load / setup, thus I like to display a loader on the button that triggers a modal.

    I am guessing this won't be possible here, as wire:target has nothing to really target. Right?

    opened by emildayan 1
Owner
null
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.

About Wire Elements Modal Wire Elements Modal is a Livewire component that provides you with a modal that supports multiple child modals while maintai

Wire Elements 806 Jan 6, 2023
Dynamic Laravel Livewire Bootstrap toasts.

Laravel Livewire Toasts This package allows you to dynamically show Bootstrap toasts via Laravel Livewire components. Documentation Requirements Insta

null 13 Nov 12, 2022
A laravel Livewire Dynamic Selects with multiple selects depending on each other values, with infinite levels and totally configurable.

Livewire Combobox: A dynamic selects for Laravel Livewire A Laravel Livewire multiple selects depending on each other values, with infinite levels of

Damián Aguilar 25 Oct 30, 2022
A dynamic table component for Laravel Livewire - For Slack access, visit:

A dynamic Laravel Livewire component for data tables. Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository Installation You can insta

Anthony Rappa 1.3k Jan 1, 2023
A dynamic Laravel Livewire component for multi steps form

Livewire component that provides you with a wizard that supports multiple steps form while maintaining state.

Vildan Bina 233 Jan 4, 2023
Laravel-comments-livewire - Livewire components for the laravel-comments package

Associate comments and reactions with Eloquent models This package contains Livewire components to be used with the spatie/laravel-comments package. S

Spatie 15 Jan 18, 2022
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
Laravel UI, Auth, & CRUD scaffolding package using Bootstrap & Livewire.

bastinald/ux Laravel UI, Auth, & CRUD scaffolding package using Bootstrap & Livewire. Features Automatic migrations Automatic routing Automatic passwo

null 33 Nov 26, 2022
Sweetalert and Toaster notifications for Laravel livewire with support for tailwind and bootstrap.

Larabell Integrate livewire with sweetalert. Installation How to use Sweetalert Toast Available configuration Installation composer require simtabi/la

Simtabi 3 Jul 27, 2022
Free and open-source Laravel admin dashboard interface built with Livewire & Alpine.js based on Bootstrap 5

Volt Dashboard Laravel Free Frontend Web App for Laravel with Livewire & Alpine.js Never start a development project from scratch again. We've partner

Themesberg 200 Jan 4, 2023
A Laravel starter kit with auth scaffolding using Livewire & Bootstrap.

Zephyr This package is a Laravel starter kit with auth scaffolding using Livewire & Bootstrap. It was created for people who prefer using Livewire & B

null 23 Aug 26, 2022
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Livewire 17.7k Jan 1, 2023
This package provides a console command to convert dynamic JS/CSS to static JS/CSS assets.

Laravel Nova Search This package provides a console command to convert dynamic JS/CSS to static JS/CSS assets. Requirements laravel-mix v6.0+ php 7.3+

Akki Khare 3 Jul 19, 2022
Jumpstart your web development journey with the HALT Stack Starter Kit, a one-command solution for creating dynamic, scalable, and clean web applications.

Welcome to the HALT Stack Starter Kit! This kit is designed to help you kickstart your web development projects using the HALT Stack, a powerful combi

HALT Stack 6 Jun 7, 2023
A TALL (Tailwind CSS, Alpine.js, Laravel and Livewire) Preset for Laravel

Laravel TALL Preset A front-end preset for Laravel to scaffold an application using the TALL stack, jumpstarting your application's development. If yo

Laravel Frontend Presets 1.8k Jan 7, 2023
Laravel Livewire Excel Upload with Progressbar

Laravel Livewire Excel Upload with Progressbar This is sample project, that explains how to import Excel files with progress bar Steps to run project

Prabakaran T 5 Oct 6, 2022
Belich Tables: a datatable package for Laravel Livewire

Belich Tables is a Laravel package base on Livewire and AlpineJS that allows you to create scaffold datatables with search, column sort, filters, pagination, etc...

Damián Aguilar 11 Aug 26, 2022
Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

null 22 Oct 6, 2022
Auto generate routes for Laravel Livewire components

livewire-auto-routes Auto generate routes for Laravel Livewire Components. Requirements Livewire 2 Laravel 8 php 8 Installation composer require tanth

Tina Hammar 19 May 11, 2022