Skip to content

Commit

Permalink
feat: Add support for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Jul 24, 2024
1 parent 0f7f240 commit 3eb417d
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 107 deletions.
15 changes: 8 additions & 7 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: 2

updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "03:00"
open-pull-requests-limit: 10
target-branch: develop
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
time: "03:00"
open-pull-requests-limit: 10
target-branch: main
28 changes: 21 additions & 7 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
name: PHPStan

on:
push:
pull_request:
on: [push, pull_request]

jobs:
phpstan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
fail-fast: true
matrix:
php: [8.1, 8.2]
laravel: [9.*, 10.*]
dependency-version: [prefer-stable]
laravel: [9.*, 10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
exclude:
- laravel: 11.*
php: 8.1
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: none

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

- name: Run PHPStan
run: composer stan
27 changes: 23 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,40 @@ on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2]
laravel: [9.*, 10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
exclude:
- laravel: 11.*
php: 8.1
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
tools: composer:v2
coverage: none

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: composer pest
run: vendor/bin/pest
28 changes: 28 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ $plan = Plan::find(1);
$plan->features;
// Get all plan subscriptions
$plan->planSubscriptions;
$plan->subscriptions;
// Check if the plan is free
$plan->isFree();
Expand All @@ -130,7 +130,7 @@ $plan->hasTrial();
$plan->hasGrace();
```
Both `$plan->features` and `$plan->planSubscriptions` are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. `$plan->features()->where('name', 'listing_title_bold')->first()`.
Both `$plan->features` and `$plan->subscriptions` are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. `$plan->features()->where('name', 'listing_title_bold')->first()`.
### Get Feature Value
Expand Down Expand Up @@ -181,7 +181,7 @@ $subscription = Subscription::find(1);
$subscription->changePlan($plan);
```
If both plans (current and new plan) have the same billing frequency (e.g., `invoice_period` and `invoice_interval`) the subscription will retain the same billing dates. If the plans don't have the same billing frequency, the subscription will have the new plan billing frequency, starting on the day of the change and _the subscription usage data will be cleared_. Also if the new plan has a trial period and it's a new subscription, the trial period will be applied.
If both plans (current and new plan) have the same billing frequency (e.g., `invoice_period` and `invoice_interval`) the subscription will retain the same billing dates. If the plans don't have the same billing frequency, the subscription will have the new plan billing frequency, starting on the day of the change and _the subscription usage data will be cleared_. Also, if the new plan has a trial period, and it's a new subscription, the trial period will be applied.
### Feature Options
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
],
"require": {
"php": "^8.1",
"illuminate/console": "^9.0|^10.0",
"illuminate/container": "^9.0|^10.0",
"illuminate/database": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/console": "^9.0|^10.0|^11.0",
"illuminate/container": "^9.0|^10.0|^11.0",
"illuminate/database": "^9.0|^10.0|^11.0",
"illuminate/support": "^9.0|^10.0|^11.0",
"spatie/eloquent-sortable": "^4.0.0",
"spatie/laravel-package-tools": "^1.16",
"spatie/laravel-sluggable": "^3.4.2",
"spatie/laravel-translatable": "^6.5.0"
},
"require-dev": {
"laravel/pint": "^1.13",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.0|^8.0",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^7.0|^8.0|^9.0",
"pestphp/pest": "^2.18"
},
"autoload": {
Expand Down
8 changes: 4 additions & 4 deletions database/migrations/create_plan_features_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravelcm\Subscriptions\Models\Plan;

return new class () extends Migration {
return new class() extends Migration
{
public function up(): void
{
Schema::create(config('laravel-subscriptions.tables.features'), function (Blueprint $table): void {
$table->id();

$table->foreignIdFor(Plan::class);
$table->foreignIdFor(config('laravel-subscriptions.models.plan'));
$table->json('name');
$table->string('slug')->unique();
$table->json('description')->nullable();
Expand Down
11 changes: 5 additions & 6 deletions database/migrations/create_plan_subscription_usage_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravelcm\Subscriptions\Models\Feature;
use Laravelcm\Subscriptions\Models\Subscription;

return new class () extends Migration {
return new class() extends Migration
{
public function up(): void
{
Schema::create(config('laravel-subscriptions.tables.subscription_usage'), function (Blueprint $table): void {
$table->id();

$table->foreignIdFor(Subscription::class);
$table->foreignIdFor(Feature::class);
$table->foreignIdFor(config('laravel-subscriptions.models.subscription'));
$table->foreignIdFor(config('laravel-subscriptions.models.feature'));
$table->unsignedSmallInteger('used');
$table->string('timezone')->nullable();

Expand Down
8 changes: 4 additions & 4 deletions database/migrations/create_plan_subscriptions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravelcm\Subscriptions\Models\Plan;

return new class () extends Migration {
return new class() extends Migration
{
public function up(): void
{
Schema::create(config('laravel-subscriptions.tables.subscriptions'), function (Blueprint $table): void {
$table->id();

$table->morphs('subscriber');
$table->foreignIdFor(Plan::class);
$table->foreignIdFor(config('laravel-subscriptions.models.plan'));
$table->json('name');
$table->string('slug')->unique();
$table->json('description')->nullable();
Expand Down
6 changes: 3 additions & 3 deletions database/migrations/create_plans_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravelcm\Subscriptions\Interval;

return new class () extends Migration {
return new class() extends Migration
{
public function up(): void
{
Schema::create(config('laravel-subscriptions.tables.plans'), function (Blueprint $table): void {
Expand Down Expand Up @@ -37,7 +38,6 @@ public function up(): void
});
}


public function down(): void
{
Schema::dropIfExists(config('laravel-subscriptions.tables.plans'));
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon

parameters:

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected static function boot(): void
{
parent::boot();

static::deleted(function (Plan $plan): void {
static::deleted(function ($plan): void {
$plan->features()->delete();
$plan->subscriptions()->delete();
});
Expand Down
Loading

0 comments on commit 3eb417d

Please sign in to comment.