承接 mozhuilungdsuo/livewire-bootstrap-modal 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mozhuilungdsuo/livewire-bootstrap-modal

最新稳定版本:v1.0.5

Composer 安装命令:

composer require mozhuilungdsuo/livewire-bootstrap-modal

包简介

Dynamic Laravel Livewire 3 Bootstrap modals.

README 文档

README

This package allows you to dynamically show your Laravel Livewire 3 components inside Bootstrap modals.

Warning: This package is not backward compatible with Livewire 2.

Documentation

Requirements

  • Bootstrap 5 must be installed via webpack first

Installation

Require the package:

composer require mozhuilungdsuo/livewire-bootstrap-modal

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

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

Require ../../vendor/mozhuilungdsuo/livewire-bootstrap-modal/resources/js/modals in your app javascript file:

import('@popperjs/core');
import '../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js';
import '../../vendor/mozhuilungdsuo/livewire-bootstrap-modal/resources/js/modals.js';

Usage

Modal Views

Make a Livewire component you want to show as a modal. The view for this component must use the Bootstrap modal-dialog container:

<div>

        <div class="modal-header">
            <h5 class="modal-title">Modal title</h5>
            <button type="button" class="btn-close" wire:click="$dispatch('hideModal')" aria-label="Close"></button>
        </div>
        <div class="modal-body">
            <p>Modal body text goes here.</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary"  wire:click="$dispatch('hideModal')">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
</div>
 

To call from a normal blade view

<button type="button" onclick="Livewire.dispatch('showModal', {data: {'alias' : 'modals.example'}})">
                            Click me to open modal
                        </button>

Showing Modals

Show a modal by emitting the showModal event with the component alias:

<div>
    <button type="button"wire:click="$dispatch('showModal', {data: {'alias' : 'modals.example'}})">
Click me
    </button>
</div>

Mount Parameters

Pass parameters to the component mount method after the alias:

<div>
    <button type="button"wire:click="$dispatch('showModal', {data: {'alias' : 'modals.example','params' :{'name':'test'},'backdrop':'static',message:'Are you sure?'}})">
Click me
    </button>
</div>
- Note 'backdrop':'static',message:'Are you sure?' are optional 

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

namespace App\Http\Livewire\Users;

use App\Models\User;
use Livewire\Component;

class Update extends Component
{
    public $user;
    
    public function mount(User $user)
    {
        $this->user = $user;
    }
    
    public function render()
    {
        return view('users.update');
    }
}

Hiding Modals

Hide the currently open modal by emitting the hideModal event:

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

Emitting Events

You can emit events inside your views:

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

Or inside your components, just like any normal Livewire event:

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

    // save the record

    $this->dispatch('hideModal');
}

Publishing Assets

Custom View

Use your own modals view by publishing the package view:

php artisan vendor:publish --tag=livewire-bootstrap-modal:views

Now edit the view file inside resources/views/vendor/livewire-bootstrap-modal. The package will use this view to render the component.

统计信息

  • 总下载量: 4.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 0
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-26