承接 kikter/discussions 相关项目开发

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

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

kikter/discussions

Composer 安装命令:

composer require kikter/discussions

包简介

Discussions is a Simple Laravel Discussions Package

README 文档

README

Warning: This package is still in development and is not ready for use.

Installation

This package assumes that you have created a new Laravel application and included the TALL Stack preset in your application.

In this package we also make use of the Filament Notifications package, which is used to show alert notifications.

Notification Animated GIF

To install this package: we can do the following:

In the root directory of your app, run:

npm install alpinejs @awcodes/alpine-floating-ui postcss tailwindcss --save-dev

Then add to your main app.js

import AlpineFloatingUI from '@awcodes/alpine-floating-ui'
import NotificationsAlpinePlugin from '../../vendor/filament/notifications/dist/module.esm'

Alpine.plugin(AlpineFloatingUI)
Alpine.plugin(NotificationsAlpinePlugin)

Add the filament './vendor/filament/**/*.blade.php' folder to your tailwind asset watcher under content:

Additionally, extend some new colors in your tailwind.config.js theme 🎨

const colors = require('tailwindcss/colors')

module.exports = {
    content: [
        './resources/**/*.blade.php',
        './vendor/filament/**/*.blade.php',
    ],
    theme: {
        extend: {
            colors: {
                danger: colors.rose,
                primary: colors.blue,
                success: colors.green,
                warning: colors.yellow,
            },
        },
    },
}

Finally, add the following before the </body> tag in your app.blade.php file:

@livewire('notifications')

That's it. You're ready to start using the discussions package.

Events

The events are useful when you want to perform additional actions or trigger custom logic based on the creation of a new discussion or post like sending an email notification to the discussion participants.

Event Description
Foundationapp\Discussions\Events\NewDiscussionCreated Dispatched when a new discussion is created.
Foundationapp\Discussions\Events\NewDiscussionPostCreated Dispatched when a new discussion post is created.

Events Usage

The event(new NewDiscussionCreated($discussion)); is dispatched after a new discussion is created. You can listen for this event in your application and perform any custom logic as needed. The same applies to the NewDiscussionPostCreated event which is dispatched after a new discussion post is created.

Creating a Listener for the NewDiscussionCreated Event

To create a listener to handle the NewDiscussionCreated event, follow these steps:

  1. Create a Listener class Create a new class for your listener in the appropriate directory (e.g., app/Listeners). The class should implement the handle() method, which will receive the NewDiscussionCreated event as a parameter.

    <?php
    namespace App\Listeners;
    
    use Foundationapp\Discussions\Events\NewDiscussionCreated;
    
    class CustomNewDiscussionListener
    {
        public function handle(NewDiscussionCreated $event)
        {
            // Your custom logic here
        }
    }
  2. Implement your custom logic Inside the handle() method, you can access the discussion property of the event and perform any custom logic as needed.

    public function handle(NewDiscussionCreated $event)
    {
        $discussion = $event->discussion;
        // Perform custom actions based on the new discussion
    }
  3. Register the Listener To register the listener, add it to the listen property of the EventServiceProvider class located at app/Providers/EventServiceProvider.php.

    protected $listen = [
        NewDiscussionCreated::class => [
            CustomNewDiscussionListener::class,
        ],
    ];
  4. (Optional) Queue the Listener If you want your listener to be queued for asynchronous processing, you can implement the ShouldQueue interface and use the Queueable trait in your listener class.

    <?php
    namespace App\Listeners;
    
    use Foundationapp\Discussions\Events\NewDiscussionCreated;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Queue\InteractsWithQueue;
    
    class CustomNewDiscussionListener implements ShouldQueue
    {
        use InteractsWithQueue;
    
        public function handle(NewDiscussionCreated $event)
        {
            // Your custom logic here
        }
    }

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-05-07