Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `sweet-alert` will be documented in this file.

## v7.3.0 - 2026-03-19
- Added Laravel 13 Support
- Updated bundled SweetAlert2
- Added Laravel Boost AI guidelines and Boost Skill
- Docs Updated

## v7.2.0 - 2024-06-15
- Added Laravel 11 Support
- Upgraded SweetAlert2 to latest version
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require": {
"php": "^7.2|^8.0|^8.1|^8.2|^8.3",
"laravel/framework": "^5.6|^6.0|^7.0|^8.0|^9.0|^9.11|9.14.*|^10.0|^11.0|^12.0"
"laravel/framework": "^5.6|^6.0|^7.0|^8.0|^9.0|^9.11|9.14.*|^10.0|^11.0|^12.0|^13.0"
},
"require-dev": {
"symfony/thanks": "^1.0"
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `sweet-alert` will be documented in this file.

## v7.3.0 - 2026-03-19
- Added Laravel 13 Support
- Updated bundled SweetAlert2
- Added Laravel Boost AI guidelines and Boost Skill
- Docs Updated

## v7.2.0 - 2024-06-15
- Added Laravel 11 Support
- Upgraded SweetAlert2 to latest version
Expand Down
214 changes: 214 additions & 0 deletions plans/update-for-laravel-13-and-ai-boost.plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
++---
name: Update package for Laravel 13 support and add Laravel Boost AI guidelines & skills
overview: Add Laravel 13 compatibility, update bundled SweetAlert2 JS, and publish Boost AI guidelines + Agent Skills for Laravel Boost integration.
todos:
- id: research-repo-and-guidelines
content: Deeply inspect repository, existing service provider, config, and bundled JS; read Laravel Boost third-party package AI guidelines and summarize exact files to create/modify.
status: pending
- id: update-composer-for-laravel-13
content: Update `composer.json` to advertise `laravel/framework: ^13.0` compatibility; run `composer validate` and adjust PHP constraints if requested.
status: pending
- id: update-sweetalert2-asset
content: Replace `resources/js/sweetalert.all.js` with the targeted SweetAlert2 distribution (identify exact upstream version), and verify blade references and `Swal.fire` usage.
status: pending
- id: add-boost-guidelines
content: Add `resources/boost/guidelines/core.blade.php` describing package features, usage, publishable assets, config keys and common integration patterns (include code snippets mirroring `alert()` helper usage).
status: pending
- id: add-boost-skill
content: Add `resources/boost/skills/sweet-alert-development/SKILL.md` with YAML frontmatter `name` and `description`, features list, and concise examples for tasks (publishing assets, using helpers, customizing theme).
status: pending
- id: docs-and-changelog
content: Update `docs/usage.md`, `CHANGELOG.md`, and `readme.md` with Laravel 13 notes and SweetAlert2 upgrade notes; add upgrade guidance for users.
status: pending
- id: tests-and-ci
content: Add minimal CI checks (composer validate, php -l or static checks) and feature test(s) verifying provider registration and asset publishing; run locally/CI.
status: pending
- id: release-pr
content: Prepare a draft changelog entry and open a PR with the changes; include migration notes and a compatibility checklist for maintainers.
status: pending
isProject: false
---

## Goal

Bring `realrashid/sweet-alert` fully compatible with Laravel 13, update the bundled SweetAlert2 JavaScript to a maintained upstream release, and add Laravel Boost third-party AI guidelines + a Boost Skill so IDE AI agents can reason about and automate usage for this package.

## Codebase context

### Patterns to mirror
- `composer.json` — current compatibility constraints and `extra.laravel.providers`/`aliases` usage.
- `src/SweetAlertServiceProvider.php` — package boot/register lifecycle and publishing groups.
- `resources/js/sweetalert.all.js` — currently bundles SweetAlert2 v11.7.20; will be replaced with the chosen upstream bundle.
- `resources/views/alert.blade.php` — blade integration that references the asset and shows `Swal.fire(...)` usage.
- `config/sweetalert.php` — package configuration keys to enumerate in guidelines.

These files teach how the package registers itself, publishes assets, and how developers consume the package from Blade.

### Existing models / migrations / relationships

None — this package does not interact with a database schema.

### Route + middleware context

This package does not register routes or middleware. Publishing is performed by the service provider using the `publishes()` method.

### Testing patterns

The repository currently lacks an automated test suite. Suggested minimal pattern:
- Use `composer validate` and PHP linting as CI gates.
- Add a basic PHPUnit or Pest feature test that boots a lightweight application, registers the service provider, and asserts that the view is loadable and that publishing paths are registered.

## Technical approach

Layers touched (in order):
1. `composer.json` — advertise Laravel 13, keep backwards compatibility where possible.
2. JS asset — replace `resources/js/sweetalert.all.js` with upstream SweetAlert2 distro; confirm API stability and update the `resources/views/alert.blade.php` CDN/asset references if the filename or initialization changed.
3. Add Boost AI guidelines — add `resources/boost/guidelines/core.blade.php` following Boost's "Third-Party Package AI Guidelines" template; include short overview, features, config, and usage snippets.
4. Add Boost Skill — add `resources/boost/skills/sweet-alert-development/SKILL.md` with YAML frontmatter and actionable examples (publish assets, use helper, confirm-delete attribute behavior).
5. Docs & changelog — update `docs/usage.md`, `CHANGELOG.md`, and top-level readme with upgrade notes.
6. CI/tests — add composer validation and at least one feature test to catch obvious regressions.

Rationale: Adding Boost guidelines + a skill lets Laravel Boost agents (Cursor, Claude Code, etc.) provide accurate code completions and generate correct integration snippets for this package; JS update ensures security/bugfixes and user expectations from upstream.

## Step-by-step implementation plan

### Step 1 — Update composer.json

**Files to create / modify:**
- `composer.json` — modify — add `^13.0` to `laravel/framework` requirement sequence.

**Key logic:**
- Keep existing broad compatibility (e.g. `^10.0|^11.0|^12.0|^13.0`). If you prefer exact ranges, mirror the upstream commit that bumped to Laravel 13.
- Run `composer validate` after edit; if `composer validate` fails due to PHP version constraints, discuss whether to raise `php` requirement.

**Mirrors:**
- Mirror the pattern already present in `composer.json` where older Laravel versions are listed; ensure `extra.laravel.providers` stays unchanged.

**Tests:**
- CI: `composer validate` passes.

---

### Step 2 — Update the bundled SweetAlert2 asset

**Files to create / modify:**
- `resources/js/sweetalert.all.js` — replace — use upstream SweetAlert2 distribution file for target version (example: replace v11.7.20 with chosen v12.x or latest stable release).

**Key logic:**
- Download the upstream `dist/sweetalert2.all.min.js` or equivalent and replace the file contents. Keep the same filename to avoid changing many references.
- Search Blade views and docs for uses of `Swal.fire` (already used) and verify no API-breaking calls exist in our usages.
- Update the file header comment to mention the new SweetAlert2 version.

**Mirrors:**
- Mirror the current file but use the newer upstream build; preserve existing `asset('vendor/sweetalert/sweetalert.all.js')` calls.

**Tests:**
- Manually load `resources/views/alert.blade.php` in a test-app environment or run a smoke test to ensure `Swal.fire` still works for `Session::pull('alert.config')` and confirm-delete handler.

---

### Step 3 — Add Laravel Boost AI Guidelines

**Files to create / modify:**
- `resources/boost/guidelines/core.blade.php` — create — short AI guideline file that follows Boost's "Third-Party Package AI Guidelines" examples.

**Key logic:**
- Provide a 4–8 paragraph guideline covering:
- What the package does (Blade helper to show SweetAlert2 alerts; publishable assets; config keys)
- How to install and publish assets (artisan vendor:publish tags: `sweetalert-view`, `sweetalert-config`, `sweetalert-asset`)
- Typical usage examples: using the `alert()` helper in controllers, using `data-confirm-delete` attribute in anchors, and customizing `config('sweetalert.theme')`.
- Any caveats for Laravel 13 (if present) or setup steps (e.g. enable `alwaysLoadJS` vs `neverLoadJS`).

**Mirrors:**
- Example template in Boost docs: put `resources/boost/guidelines/core.blade.php` and keep the content concise and prescriptive.

**Tests:**
- None (guidelines are documentation for agents), but include this file in package releases so `boost:install` picks it up.

---

### Step 4 — Add a Boost Skill

**Files to create / modify:**
- `resources/boost/skills/sweet-alert-development/SKILL.md` — create — include YAML frontmatter `name` and `description` and short actionable tasks and examples.

**Key logic:**
- Frontmatter required fields: `name` and `description`.
- Content sections: "When to use this skill", "Features", and code snippets showing how to create alert calls, how to publish assets, and how to add `data-confirm-delete` anchors.

**Mirrors:**
- Use the Boost skill examples in the docs; structure the skill so it can be picked up automatically by `boost:install`.

**Tests:**
- None, but confirm `boost:install` will detect the guidelines and skill when included in a consumer project.

---

### Step 5 — Update docs, changelog, README

**Files to create / modify:**
- `docs/usage.md` — modify — add Laravel 13 compatibility notes and SweetAlert2 version used.
- `CHANGELOG.md` — modify — add an entry for Laravel 13 support and the JS update.
- `readme.md` — modify — small note about Boost support and how to run `boost:install` to pick up package guidelines.

**Key logic:**
- Explain upgrade steps for end users, any breaking changes, and how to re-publish assets.

**Tests:**
- Visual/manual review.

---

### Step 6 — Tests & CI

**Files to create / modify:**
- `.github/workflows/ci.yml` — create — minimal CI that runs `composer validate`, `composer install --no-interaction`, and `php -l` (lint) or `vendor/bin/pest --filter` if tests added.
- `tests/Feature/ProviderRegistrationTest.php` — create — if adding tests; lightweight test to assert provider binding.

**Key logic:**
- CI ensures we do not ship invalid composer metadata and that the package loads without syntax errors.

**Tests:**
- `unauthenticated -> 401` tests are not applicable. Instead test:
- Provider registers the `alert` singleton and alias `Alert` resolves.
- Publishing groups include `sweetalert-view`, `sweetalert-config`, `sweetalert-asset`.

---

## Files to create or modify (complete list)

| File | Action | Mirrors | Notes |
|------|--------|---------|-------|
| `composer.json` | modify | original `composer.json` | Add `^13.0` to `laravel/framework` requirement; run `composer validate`. |
| `resources/js/sweetalert.all.js` | modify | upstream SweetAlert2 distribution | Replace with vetted upstream bundle; keep same filename to avoid downstream breakage. |
| `resources/boost/guidelines/core.blade.php` | create | Laravel Boost docs example | Third-party package AI guideline for Boost. |
| `resources/boost/skills/sweet-alert-development/SKILL.md` | create | Boost skill examples | Skill frontmatter + examples. |
| `docs/usage.md` | modify | `docs/usage.md` | Add upgrade instructions. |
| `CHANGELOG.md` | modify | existing changelog | Add Laravel 13 + SweetAlert2 upgrade notes. |
| `.github/workflows/ci.yml` | create | standard CI patterns | Run `composer validate`, `php -l`, and tests if available. |

## Test cases (complete list)

| Test | Type | Assertion |
|------|------|-----------|
| Provider registers `alert` | unit/feature | `assertTrue(app()->bound('alert'))` and facade resolves `Alert::` |
| Publishing groups present | feature | `assertContains('sweetalert-config', array_keys($provider->publishes()))` or check `artisan vendor:publish --list` output in integration test |
| SweetAlert2 asset loads | smoke | Render view containing `asset('vendor/sweetalert/sweetalert.all.js')` and assert path exists in filesystem after `vendor:publish`. |

## Open questions / decisions needed

- Which SweetAlert2 upstream version should we target (exact semver)? (e.g., `v11.7.20` -> `v12.x` or latest stable)
https://cdn.jsdelivr.net/npm/sweetalert2@11

- Do we want to bump the `php` requirement in `composer.json` (current `^7.2|^8.0|...`)? Laravel 13 may require a minimum PHP version — if so, what minimum PHP version should this package require?
laravel 13 require i think 8.3 or 8.4
- Confirm whether we should fix or refactor the `$this->app->bind(...)` call in `SweetAlertServiceProvider::register()` (it currently passes three arguments; it may be a historical pattern but deserves review).

leave it as it is.

## NOT in scope

- Implementing the full test suite for the package (beyond minimal CI and a couple of smoke tests).
- Changing public APIs of the package (we aim for a compatibility upgrade only).

---
8 changes: 2 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ composer require realrashid/sweet-alert
<h3 align="center">
<a href="https://realrashid.github.io/sweet-alert" target="_blank">Documentation</a>
</h3>
<br>

<br>
<h3 align="center">
<a href="https://github.com/sweetalert2/sweetalert2" target="_blank">Checkout the Js Library</a>
</h3>
<br>

<br>

## Sponsors
Expand Down
58 changes: 58 additions & 0 deletions resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{--
Laravel Boost third-party package AI guideline for realrashid/sweet-alert
Provides concise instructions and examples for AI agents to integrate this package.
--}}

# Sweet Alert (realrashid/sweet-alert)

This package provides Blade helpers and published assets to easily display SweetAlert2 popups and toasts from Laravel applications. It publishes view templates, configuration, and JavaScript/CSS assets so applications can customize themes and loading behavior.

## Features

- Helper API: `alert()` helper and `RealRashid\SweetAlert\Facades\Alert` facade for dispatching alerts from controllers.
- Publishable resources: view templates, config, and bundled JS assets (publish tags listed below).
- Blade view integration: a Blade view injects `Swal.fire(...)` calls when `Session::has('alert.config')` or `alert()->delete()` flows are used.

## Publishable tags

- `sweetalert-view` — publishes `resources/views/vendor/sweetalert`
- `sweetalert-config` — publishes `config/sweetalert.php`
- `sweetalert-asset` — publishes the JS/CSS assets to `public/vendor/sweetalert`

Example: `php artisan vendor:publish --provider="RealRashid\SweetAlert\SweetAlertServiceProvider" --tag="sweetalert-config"`

## Typical usage

1. Install the package via Composer and (optionally) publish assets.

```php
// In a controller
use RealRashid\SweetAlert\Facades\Alert;

public function destroy($id)
{
// Perform deletion logic...
Alert::success('Deleted', 'Record was deleted successfully');
return redirect()->route('items.index');
}
```

2. In Blade, the package's `alert` view will automatically enqueue the required JS/CSS depending on `config('sweetalert')` settings. The view uses `asset('vendor/sweetalert/sweetalert.all.js')` by default.

3. To add client-side confirm-on-delete behavior, the package supports `data-confirm-delete` anchors. Example:

```html
<a href="{{ route('items.destroy', $item->id) }}" data-confirm-delete>Delete</a>
```

When the attribute is present, the package injects a `Swal.fire({ ... })` confirmation and, if confirmed, submits a hidden form to perform the deletion.

## Configuration hints

- `alwaysLoadJS`, `neverLoadJS` — controls whether the bundled JS is loaded automatically.
- `theme` — controls which SweetAlert2 theme to load from CDN when set.

## Notes for Laravel 13

- The package advertises Laravel 13 compatibility; ensure your project PHP requirement matches Laravel 13's minimum if you upgrade the application.
- This file is short and prescriptive so AI agents can provide correct integration snippets and publishing commands.
46 changes: 46 additions & 0 deletions resources/boost/skills/sweet-alert-development/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: sweet-alert-development
description: Build and work with Sweet Alert features, including publishing assets, using the helper facade, and adding confirm-delete UI patterns.
---

# Sweet Alert Development

## When to use this skill

Use this skill when implementing or modifying UI flows that require modal confirmations, toasts, or inline alerts using the `realrashid/sweet-alert` Laravel package.

## Features

- Publish package views and assets (`vendor:publish` tags: `sweetalert-view`, `sweetalert-config`, `sweetalert-asset`).
- Programmatically trigger alerts using the `alert()` helper or `RealRashid\SweetAlert\Facades\Alert`.
- Client-side `data-confirm-delete` attribute support for anchors that need confirmation before HTTP DELETE.

## Examples

### Publishing configuration

```bash
php artisan vendor:publish --provider="RealRashid\SweetAlert\SweetAlertServiceProvider" --tag="sweetalert-config"
```

### Triggering an alert from a controller

```php
use RealRashid\SweetAlert\Facades\Alert;

Alert::success('Saved', 'Your changes were saved successfully');
return redirect()->back();
```

### Using confirm-delete anchor in Blade

```blade
<a href="{{ route('posts.destroy', $post->id) }}" data-confirm-delete>Delete post</a>
```

When the user clicks this link, SweetAlert2 will prompt for confirmation and, upon confirm, the package will submit a DELETE form.

## Implementation tips for AI agents

- Prefer `asset('vendor/sweetalert/sweetalert.all.js')` references for the bundled file to avoid breaking changes when replacing the upstream JS bundle.
- Suggest `php artisan boost:install` to users who want Laravel Boost to pick up this package's guidelines and skills automatically.
6 changes: 3 additions & 3 deletions resources/js/sweetalert.all.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/Feature/ProviderRegistrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use RealRashid\SweetAlert\SweetAlertServiceProvider;

class ProviderRegistrationTest extends TestCase
{
public function test_service_provider_class_exists()
{
$this->assertTrue(class_exists(SweetAlertServiceProvider::class));
}
}
Loading