polashmahmud/inertia-toast 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

polashmahmud/inertia-toast

Composer 安装命令:

composer require polashmahmud/inertia-toast

包简介

Simple InertiaJS + Vue + Laravel toast notification system using vue-sonner.

README 文档

README

Simple, zero-boilerplate toast notifications for Laravel + Inertia.js (Vue) using vue-sonner.

It ships with:

  • Laravel middleware that exposes flash messages to Inertia
  • A tiny Vue plugin that auto-mounts the Toaster and listens to Inertia navigations
  • A publishable config to customize position, theme, and behavior

Installation

  1. Install the package
composer require polashmahmud/inertia-toast:^2.0.1
  1. Install the client dependency
npm install vue-sonner
  1. Add the plugin in your Vue app (auto-mounts Toaster)

resources/js/app.ts

import "vue-sonner/style.css";
import notification from "@inertia-toast/plugins";

createInertiaApp({
  // ...
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .use(notification)
      .mount(el);
  },
});

You do NOT need to render <Toaster /> yourself—the plugin does it for you.

  1. Vite alias

vite.config.ts

import path from "path";

export default defineConfig({
  resolve: {
    alias: {
      "@inertia-toast": path.resolve(
        __dirname,
        "vendor/polashmahmud/inertia-toast/resources/js"
      ),
    },
  },
});

Optionally, add a TypeScript path mapping for better editor DX in tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@inertia-toast/*": ["./vendor/polashmahmud/inertia-toast/resources/js/*"]
    }
  }
}
  1. Publish the config
php artisan vendor:publish --tag="inertia-toast-config"

This creates config/inertia-toast.php where you can tweak:

return [
    'position' => 'bottom-right', // top-left | top-center | top-right | bottom-left | bottom-center | bottom-right
    'closeButton' => true,
    'expand' => false,
    'theme' => 'system',          // light | dark | system
    'richColors' => true,
    'toastOptions' => [
        'style' => [],
        'class' => '',
        'descriptionClass' => '',
    ],
];

Usage

From your controller or route, flash to the session. The plugin automatically shows a toast after the Inertia visit finishes.

Minimal (string body):

return back()->with('success', 'That worked nicely');

With description (indexed array):

return back()->with('warning', ['That worked nicely', 'Please check again']);

With description (associative array):

return back()->with('error', [
        'message' => 'Something went wrong!',
        'description' => 'Please try again after 5 seconds.',
]);

Supported types: success, error, warning, info.

Custom Styling

You can customize the appearance of the toast notifications by modifying the toastOptions in config/inertia-toast.php.

'toastOptions' => [
    'style' => [
        'background' => '#fda4af',
    ],
    'class' => 'bg-red-500 text-white',
    'descriptionClass' => 'text-red-100',
],

Using Tailwind CSS

If you want to use Tailwind CSS classes in the class or descriptionClass options, you must ensure that Tailwind scans your configuration file. Add the config file path to the content array in your tailwind.config.js:

module.exports = {
  content: [
    "./resources/**/*.blade.php",
    "./resources/**/*.js",
    "./resources/**/*.vue",
    "./config/inertia-toast.php", // Add this line
  ],
  // ...
};

Troubleshooting

  • Changed config but UI didn’t update?
    • Run: php artisan optimize:clear
    • Hard refresh the browser (Disable cache in DevTools)
    • Ensure the provider is registered and alias resolves

License

MIT

polashmahmud/inertia-toast 适用场景与选型建议

polashmahmud/inertia-toast 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 337 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「notification」 「laravel」 「toast」 「vue」 「inertiajs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 polashmahmud/inertia-toast 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 polashmahmud/inertia-toast 我们能提供哪些服务?
定制开发 / 二次开发

基于 polashmahmud/inertia-toast 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-28