diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24337a5..a46b3c7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-20.04] - php: ['7.4', '8.0', '8.1'] + php: ['8.1', '8.2'] name: P${{ matrix.php }} steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d4c2fa..ff7089d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.0.0] - 2023-09-11 + +* Updated PHP requirement to 8.1 and above (7.4 and 8.0 dropped) [PR#28](https://github.com/mikebarlow/megaphone/pull/28) +* Updated to Livewire 3 [PR#28](https://github.com/mikebarlow/megaphone/pull/28) +* Updated Testbench and Pest [PR#28](https://github.com/mikebarlow/megaphone/pull/28) + ## [1.2.0] - 2023-02-25 * Removed `public $user` from component and changed loading of announcements to prevent user model data exposure. [PR #22](https://github.com/mikebarlow/megaphone/pull/22) diff --git a/README.md b/README.md index 2d6dbb1..bdeaea8 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,40 @@ Before using Megaphone, a demo is available for you to view and try the Bell Ico [View the Megaphone Demo](https://megaphone.mikebarlow.co.uk) +## Upgrade from 1.x + +Megaphone has been updated to support Livewire 3. This also means PHP requirements have been updated to match the requirements of Livewire 3 which means you need to be running PHP 8.1 or above (PHP 7.4 and 8.0 are no longer supported). +Then make sure you follow the [Livewire upgrade guide](https://livewire.laravel.com/docs/upgrading). + +Update your Megaphone requirement to 2.* by running the following command in your terminal. + +```bash + composer require mbarlow/megaphone "^2.0" +``` + +### AlpineJS + +If you previously included AlpineJS specifically for Megaphone then you can now remove that from your JS include because it is now bundled with Livewire. + +### Template Changes + +If you are using the Admin component and are running with the Megaphone views published to your resources folder, you may wish to make these manual changes. + +Changes are all to `create-announcement.blade.php` which, if published, should be found at `resources/views/vendor/megaphone/admin/create-announcement.blade.php`. + +Find `wire:model="type"` and replace it with `wire:model.live="type"`. + +Find all instances of `wire:model.lazy` and replace it with `wire:model.blur`. + ## Installation Simply require the package via composer into your Laravel app. composer require mbarlow/megaphone -If you aren't already using Laravel Livewire in your app, Megaphone should include the package via its dependency. Once composer has finished installing, make sure you run the [Livewire installation steps](https://laravel-livewire.com/docs/2.x/installation). +If you aren't already using Laravel Livewire in your app, Megaphone should include the package via its dependency. Once composer has finished installing, make sure you run the [Livewire installation steps](https://livewire.laravel.com/docs/installation). -Once Livewire has been installed, if you haven't already, ensure the [Laravel Database Notifications have been installed](https://laravel.com/docs/9.x/notifications#database-prerequisites) into your app. +Once Livewire has been installed, if you haven't already, ensure the [Laravel Database Notifications have been installed](https://laravel.com/docs/10.x/notifications#database-prerequisites) into your app. ```bash php artisan notifications:table @@ -35,7 +60,7 @@ php artisan notifications:table php artisan migrate ``` -This should create database table used to house your notifications. Next, make sure your User model (or relevant alternative model) has the notifiable trait added as mentioned in the [Laravel Documentation](https://laravel.com/docs/9.x/notifications#using-the-notifiable-trait) and also add the `HasMegaphone` trait provided by Megaphone. +This should create database table used to house your notifications. Next, make sure your User model (or relevant alternative model) has the notifiable trait added as mentioned in the [Laravel Documentation](https://laravel.com/docs/10.x/notifications#using-the-notifiable-trait) and also add the `HasMegaphone` trait provided by Megaphone. ```php ``` -### AlpineJS - -Megaphone requires AlpineJS to power some of its interactivity. If you are already using AlpineJS within your application, you can skip this step. If not you will need to [include AlpineJS into your application](https://alpinejs.dev/essentials/installation) for Megaphone to function properly. - ## Sending Notifications As default, Megaphone will only load notifications that have been registered within the Megaphone config file. Notifications shipped with Megaphone will be within `config('megaphone.types')`. This will be merged with the key values of `config('megaphone.customTypes')` to create the list of supported notifications. @@ -100,7 +121,7 @@ $notification = new \MBarlow\Megaphone\Types\Important( ); ``` -Now, simply notify the required user of the notification as per the [Laravel Documentation](https://laravel.com/docs/9.x/notifications#using-the-notifiable-trait). +Now, simply notify the required user of the notification as per the [Laravel Documentation](https://laravel.com/docs/10.x/notifications#using-the-notifiable-trait). ```php $user = \App\Models\User::find(1); diff --git a/composer.json b/composer.json index 0c2a976..0c88955 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,16 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "livewire/livewire": "^2.0" + "php": "^8.1", + "livewire/livewire": "^3.0.1" }, "require-dev": { "squizlabs/php_codesniffer": "^3.7", - "pestphp/pest-plugin-livewire": "^1.0", - "orchestra/testbench": "^6.0", - "pestphp/pest-plugin-faker": "^1.0" + "pestphp/pest-plugin-livewire": "^2.1", + "orchestra/testbench": "^8.10", + "pestphp/pest-plugin-faker": "^2.0", + "brianium/paratest": "^7.2", + "pestphp/pest": "2.16" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 79fcf38..6bf0384 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,14 @@ - - - - src/ - - - - - tests/ - - + + + + + tests/ + + + + + src/ + + diff --git a/resources/views/admin/create-announcement.blade.php b/resources/views/admin/create-announcement.blade.php index 8ef2068..9b780d0 100644 --- a/resources/views/admin/create-announcement.blade.php +++ b/resources/views/admin/create-announcement.blade.php @@ -12,7 +12,7 @@
+
- +
- +
- +
diff --git a/tests/MegaphoneComponentTest.php b/tests/MegaphoneComponentTest.php index decdb77..64e7a96 100644 --- a/tests/MegaphoneComponentTest.php +++ b/tests/MegaphoneComponentTest.php @@ -72,9 +72,10 @@ ); $user->unreadNotifications->first()->markAsRead(); + $this->livewire(Megaphone::class) ->call('loadAnnouncements', $user) - ->assertSet('unread', $user->unreadNotifications()->get()) + ->assertSet('unread', $user->announcements()->get()->whereNull('read_at')) ->assertSet('announcements', $user->readNotifications); }); @@ -95,7 +96,7 @@ $this->livewire(Megaphone::class) ->call('markAsRead', $notification) - ->assertSet('unread', $user->unreadNotifications()->get()) + ->assertSet('unread', $user->announcements()->get()->whereNull('read_at')) ->assertSet('announcements', $user->readNotifications); }); diff --git a/tests/Setup/TestCase.php b/tests/Setup/TestCase.php index 03c1255..376f583 100644 --- a/tests/Setup/TestCase.php +++ b/tests/Setup/TestCase.php @@ -7,7 +7,7 @@ use Livewire\LivewireServiceProvider; use MBarlow\Megaphone\MegaphoneServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; -use function Pest\Faker\faker; +use function Pest\Faker\fake; class TestCase extends BaseTestCase { @@ -22,7 +22,7 @@ protected function setUp(): void protected function createTestUser(): User { - $faker = faker(); + $faker = fake(); $user = new User(); $user->name = $faker->name; $user->email = $faker->email; @@ -34,7 +34,7 @@ protected function createTestUser(): User protected function createTestNotification($user, $notifClass) { - $faker = faker(); + $faker = fake(); $notification = new $notifClass( $faker->sentence,