Laravel Cloud 来了!为 Laravel 应用提供零配置的托管基础​​设施。 立即部署

Laravel Starter Kits Now Include Toast Notifications

发布日期 经过

All four official Laravel starter kits now include toast notifications out of the box. The update replaces the previous inline action messages with a consistent notification pattern across every stack. The feature was contributed by @温德尔阿德里尔

工作原理

Inertia Stacks (React, Vue, Svelte)

The Inertia-based kits use a new Inertia::flash() call on the server side to pass toast data to the frontend:

惯性 :: 闪光 'toast' ,[ '类型' => '成功' , '信息' => __ 'Profile updated.' )]);
返回 到路线 'profile.edit' (英文):

On the frontend, a useFlashToast hook listens for Inertia's flash event and triggers a Sonner toast. Here's the React implementation:

进口 { router } '@inertiajs/react' ;
进口 { useEffect } 'react' ;
进口 { toast } 'sonner' ;
进口 类型 { FlashToast } '@/types/ui' ;
出口 功能 useFlashToast () : 空白 {
使用效果 (() => {
返回 路由器。 'flash' ,( 事件 => {
常量 闪光 = (event 作为 CustomEvent ).detail?.flash;
常量 数据 = flash?.toast 作为 FlashToast | 不明确的 ;
如果 data) {
返回 ;
}
toast[data.type](data.message);
});
}, []);
}

FlashToast type supports four variants — success , info , warning , 和 error — giving you control over how notifications appear:

出口 类型 FlashToast = {
类型 : '成功' | '信息' | '警告' | '错误' ;
信息 : 细绳 ;
};

A <Toaster /> component wraps Sonner and is mounted at the app level, so toasts work on any page without additional setup.

Livewire Stack

The Livewire kit uses Flux's built-in toast component. Instead of dispatching browser events and relying on inline <x-action-message> components, you call Flux::toast() 直接地:

使用 Flux\Flux ;
Flux :: 吐司 variant : '成功' , 文本 : __ 'Profile updated.' ));

Each layout file includes a persisted toast group so notifications survive Livewire re-renders:

@persist 'toast'
< flux:toast.group >
< flux:toast />
</ flux:toast.group >
@endpersist

This replaces the previous <x-action-message> component, which displayed a temporary "Saved." message inline next to the save button.

What Changed

The toast notifications are wired up for profile updates, password changes, and email verification across all four kits. The settings controllers now flash toast data instead of relying on session status messages or Livewire event dispatches.

To add toasts to your own actions, use Inertia::flash() for the Inertia stacks or Flux::toast() for Livewire — the frontend plumbing is already in place.

Each Inertia stack uses a framework-specific Sonner port — sonner for React, vue-sonner for Vue, and svelte-sonner for Svelte — while the Livewire kit uses Flux toast components.

参考

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
了解软科技

以每小时 20 美元的价格聘请具备人工智能专业知识的 Laravel 开发人员。48 小时内即可开始工作。

访问 Acquaint Softtech
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
几天内即可获得 Laravel 代码审查徽标的专家指导

几天内即可获得 Laravel 代码审查方面的专家指导

专家级代码审查!两位拥有 10 年以上 Laravel 开发经验的开发者将为您提供清晰、实用的反馈,帮助团队构建更优质的应用程序。

几天内即可获得 Laravel 代码审查方面的专家指导
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
MongoDB 徽标

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB
Drop in comments for Filament with Commentions image

Drop in comments for Filament with Commentions

阅读文章
Laravel Starter Kits Now Include Toast Notifications image

Laravel Starter Kits Now Include Toast Notifications

阅读文章
Ship AI with Laravel: Stop Your AI Agent from Guessing image

Ship AI with Laravel: Stop Your AI Agent from Guessing

阅读文章
Laravel Cloud Adds Path Blocking to Prevent Bots From Waking Hibernated Apps image

Laravel Cloud Adds Path Blocking to Prevent Bots From Waking Hibernated Apps

阅读文章
Making Laravel MongoDB Operations Idempotent: Safe Retries for Financial Transactions image

Making Laravel MongoDB Operations Idempotent: Safe Retries for Financial Transactions

阅读文章
FormRequest Strict Mode and Queue Job Inspection in Laravel 13.4.0 image

FormRequest Strict Mode and Queue Job Inspection in Laravel 13.4.0

阅读文章