rellix/dismissibles-for-laravel
Composer 安装命令:
composer require rellix/dismissibles-for-laravel
包简介
A Laravel package for easily handling the visibility of dismissible, recurring objects like popups/notifications/modals on the server side.
关键字:
README 文档
README
A Laravel package for easily managing the visibility of your recurring, dismissible objects like popups/notifications/modals on the backend. This package does not include frontend components, so it's compatible with any frontend you can use.
📕 Table of Contents
- ✅ What problem does this solve?
- 📦 Installation
- ❓ How to use
- ❗ Good to know
- 💾 Database tables
- ☕ Buy me a coffee
✅ What problem does this solve?
Say you have a popup you want to show to every user, daily for a week. Users can dismiss it and it should not show up again for the rest of the day until the next day.
This packages handles the complex logic regarding whether the (dismissible) popup should be visible to the current user at the current moment. It basically handles the visibility of your dismissible. It's highly customizable, making it very flexible for many scenario's.
Because it's serverside we can easily get statistics like who dismissed what, when and where.
📦 Installation
- Require the package in your Laravel application
composer require rellix/dismissibles-for-laravel
- Run the migrations to create the database tables
php artisan migrate
❓ How to use
1. Add the interface and trait to any model
use Rellix\Dismissibles\Contracts\Dismisser; use Rellix\Dismissibles\Traits\HasDismissibles; class User implements Dismisser { use HasDismissibles; ... }
2. Create a dismissible (migration)
use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\DB; return new class () extends Migration { public function up(): void { DB::table('dismissibles')->insert([ 'name' => 'Test Popup', // This is your **unique** identifier 'active_from' => Date::createFromFormat('d-m-Y', '01-03-2024'), 'active_until' => null, // Optional end date 'created_at' => Date::now(), 'updated_at' => Date::now(), ]); } };
and run your created migration:
php artisan migrate
💡 You can also create/fetch a Dismissible inline using the "active"-scope and "firstOrCreate".
Dismissible::active()->firstOrCreate( ['name' => 'Test Popup'], [ 'active_from' => Date::createFromFormat('d-m-Y', '01-03-2024'), 'active_until' => null, 'created_at' => Date::now(), 'updated_at' => Date::now(), ] );
3. Check if it should be visible at the current moment
use Rellix\Dismissibles\Facades\Dismissibles; $showPopup = Dismissibles::shouldBeVisible('Test Popup', $user); // Here are some more examples, including ones with additional conditionals: $showPopup = Dismissibles::shouldBeVisible('Happy New Year 2025 Popup', $user); $showPopup = Dismissibles::shouldBeVisible('Newsletter signup modal', $user) && !$user->is_subscribed; $showPopup = Dismissibles::shouldBeVisible('Complete your profile notification', $user) && !$user->has_completed_profile; $showPopup = Dismissibles::shouldBeVisible('50% Off First Purchase Popup', $user) && !$user->has_orders; // You can also get all Dismissibles in one query (performance) and use the model methods. $dismissibles = Dismissibles::getAllFor($user);
💡 You can also use the individual models.
use Rellix\Dismissibles\Facades\Dismissibles; $popup = Dismissibles::get('Test Popup'); $showPopup = $popup->shouldBeVisibleTo($user);
4. Dismiss it for a specified period
use Rellix\Dismissibles\Facades\Dismissibles; Dismissibles::dismiss('Test Popup', $user)->untilNextWeek(); // Here's an overview of all the ways you can dismiss: Dismissibles::dismiss('Test Popup', $user) ->untilTomorrow(); ->untilNextWeek(); ->untilNextMonth(); ->untilNextQuarter(); ->untilNextYear(); ->until($dateTime); ->forHours($numberOfHours); ->forDays($numberOfDays); ->forWeeks($numberOfWeeks); ->forMonths($numberOfMonths); ->forYears($numberOfYears); ->forever();
💡 You can also use the individual models.
use Rellix\Dismissibles\Facades\Dismissibles; $popup = Dismissibles::get('Test Popup'); // Here's an overview of all the ways you can dismiss: $popup->dismissFor($user) ->untilTomorrow(); ->untilNextWeek(); ->untilNextMonth(); ->untilNextQuarter(); ->untilNextYear(); ->until($dateTime); ->forHours($numberOfHours); ->forDays($numberOfDays); ->forWeeks($numberOfWeeks); ->forMonths($numberOfMonths); ->forYears($numberOfYears); ->forever();
❗ Good to know
- The facade contains some oneliners by
$name, but you can also use the scopes/methods in theDismissibleandDismissalEloquent models as you wish for ultimate flexibility. - It's recommended to centralize dismissible names in an enum (or config)
- Need extra data regarding the dismissal? All dismiss methods allow you to pass an
$extraDataarray as last parameter which will be written to thedismissalstable as json. - Feel free to request more methods/scopes
💾 Database tables
The database structure allows you to easily track activity regarding dismissibles. Due to the extra_data column it's also very flexible!
dismissibles (popups, notifications, modals)
| id | name | active_from | active_until | created_at | updated_at |
|---|---|---|---|---|---|
| 3 | Test Popup | 2024-03-01 00:00:00 | null | 2023-12-15 17:35:54 | 2023-12-15 17:35:54 |
dismissals (activity)
| id | dismissible_id | dismisser_type | dismisser_id | dismissed_until | extra_data | created_at | updated_at |
|---|---|---|---|---|---|---|---|
| 15 | 3 | App\Models\User | 328 | 2024-04-29 00:00:00 | "{"route":"home.index"}" | 2024-04-28 17:35:54 | 2024-04-28 17:35:54 |
☕ Buy me a coffee
If you like this package, consider buying me a coffee :-).
rellix/dismissibles-for-laravel 适用场景与选型建议
rellix/dismissibles-for-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 156 次下载、GitHub Stars 达 43, 最近一次更新时间为 2024 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notification」 「laravel」 「modal」 「recurring」 「popup」 「serverside」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rellix/dismissibles-for-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rellix/dismissibles-for-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rellix/dismissibles-for-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Fork from ghosh/Micromodal. Tiny, dependency-free javascript library for creating accessible modal dialogs.
Make Filament modals draggable.
A Filament form component that displays repeater items in a table with modal-based editing.
A Laravel Nova field. To create a modal for creating or viewing related HasMany records without leaving the index page
Apple Push Notification & Feedback Provider
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-29
