Skip to content
Open
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
31 changes: 31 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: analyse

on:
push:
paths:
- '**.php'
- '.github/workflows/analyse.yml'
- 'phpstan.neon.dist'
- 'composer.json'
- 'composer.lock'

jobs:
analyse:
name: phpstan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run PHPStan
run: vendor/bin/phpstan analyse --error-format=github
33 changes: 0 additions & 33 deletions .github/workflows/psalm.yml

This file was deleted.

51 changes: 26 additions & 25 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,42 @@ on:
push:
branches:
- main
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
branches:
- main
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.4, 8.3, 8.2, 8.1, 8.0]
laravel: ['9.*', '10.*', '11.*', '12.*']
php: [8.5, 8.4, 8.3]
laravel: ['11.*', '12.*']
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 12.*
testbench: 10.*
carbon: ^3.8.4
- laravel: 11.*
testbench: 9.*
carbon: ^3.8.4
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
testbench: ^10.0
- laravel: 11.*
php: 8.0
- laravel: 12.*
php: 8.1
- laravel: 12.*
php: 8.0
testbench: ^9.1.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -63,8 +61,11 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/pest --ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ vendor
node_modules
.php-cs-fixer.cache
.phpunit.cache/test-results
.claude/
73 changes: 65 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@ You can install the package via composer:
composer require maize-tech/laravel-markable
```

You can publish and run the migrations with:
```bash
php artisan markable:install
```

The install command will automatically publish the config file. Then publish only the migrations you need:

```bash
php artisan vendor:publish --tag="markable-migration-bookmark" # publishes bookmark migration
php artisan vendor:publish --tag="markable-migration-favorite" # publishes favorite migration
php artisan vendor:publish --tag="markable-migration-like" # publishes like migration
php artisan vendor:publish --tag="markable-migration-reaction" # publishes reaction migration
php artisan vendor:publish --tag="markable-migration-bookmark"
```

php artisan migrate
```bash
php artisan vendor:publish --tag="markable-migration-favorite"
```

You can publish the config file with:
```bash
php artisan vendor:publish --tag="markable-config"
php artisan vendor:publish --tag="markable-migration-like"
```

```bash
php artisan vendor:publish --tag="markable-migration-reaction"
```

```bash
php artisan migrate
```

This is the content of the published config file:
Expand Down Expand Up @@ -287,6 +297,53 @@ $user = auth()->user();
Reaction::add($post, $user, 'random_value'); // adds the 'random_value' reaction to the post for the given user
```

### Using BackedEnum values

You can use a `BackedEnum` class as the `allowed_values` for a mark. This lets you leverage PHP enums for type-safe mark values instead of plain strings.

Define your enum:

``` php
// app/Enums/ReactionType.php
enum ReactionType: string
{
case Like = 'like';
case Love = 'love';
case Wow = 'wow';
}
```

Set the enum class as the allowed values in `config/markable.php`:

``` php
'allowed_values' => [
'reaction' => \App\Enums\ReactionType::class,
],
```

All mark methods accept `null|string|\BackedEnum`, so you can pass enum cases directly:

``` php
use App\Enums\ReactionType;
use App\Models\Post;
use Maize\Markable\Models\Reaction;

$post = Post::firstOrFail();
$user = auth()->user();

Reaction::add($post, $user, ReactionType::Like);
Reaction::remove($post, $user, ReactionType::Like);
Reaction::toggle($post, $user, ReactionType::Love);
Reaction::has($post, $user, ReactionType::Like); // bool
Reaction::count($post, ReactionType::Wow); // int
```

The dynamic Eloquent scopes also accept enum cases:

``` php
Post::whereHasReaction($user, ReactionType::Like)->get();
```

### Retrieve the list of marks of an entity with eloquent

``` php
Expand Down
25 changes: 14 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
}
],
"require": {
"php": "^8.0",
"illuminate/database": "^9.0|^10.0|^11.0|^12.0",
"illuminate/support": "^9.0|^10.0|^11.0|^12.0",
"php": "^8.3",
"illuminate/database": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0",
"spatie/laravel-package-tools": "^1.92.6"
},
"require-dev": {
"laravel/pint": "^1.0",
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
"phpunit/phpunit": "^9.5|^10.5|^11.5.3",
"spatie/laravel-ray": "^1.29",
"vimeo/psalm": "^4.22|^5.22|^6.6"
"orchestra/testbench": "^9.1|^10.0",
"pestphp/pest": "^3",
"pestphp/pest-plugin-laravel": "^3",
"larastan/larastan": "^2.9|^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -49,12 +49,15 @@
},
"scripts": {
"format": "vendor/bin/pint",
"psalm": "vendor/bin/psalm",
"test": "vendor/bin/phpunit --colors=always",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest --colors=always",
"test-coverage": "vendor/bin/pest --coverage-html coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- vendor/larastan/larastan/extension.neon

parameters:
paths:
- src

level: 5
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Maize Test Suite">
<directory>tests</directory>
Expand Down
16 changes: 0 additions & 16 deletions psalm.xml.dist

This file was deleted.

Loading
Loading