Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Laravel 11 #28

Merged
merged 7 commits into from
Mar 16, 2024
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
14 changes: 11 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ jobs:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
laravel: [10.*]

name: P${{ matrix.php }} - L${{ matrix.laravel }}
laravel: ["^11.0", "^10.0"]
include:
- laravel: "^11.0"
testbench: 9.*
- laravel: "^10.0"
testbench: 8.*
exclude:
- laravel: "^11.0"
php: 8.1

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

steps:
- name: Checkout code
Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
],
"require": {
"php": "^8.1",
"composer/semver": "^3.3.2",
"filament/filament": "^3.2",
"flowframe/laravel-trend": "^0.1.5",
"illuminate/contracts": "^10.0",
"illuminate/database": "^10.0",
"jessarcher/laravel-castable-data-transfer-object": "^2.3",
"laravel/prompts": "^0.1.15",
"laravel/sanctum": "^3.2.1",
"flowframe/laravel-trend": "^0.1.5|^0.2",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/database": "^10.0|^11.0",
"laravel/prompts": "^0.1.16",
"laravel/sanctum": "^3.2.1|^4.0",
"laravel/socialite": "^5.6.1",
"livewire/livewire": "^3.4",
"nunomaduro/termwind": "^1.15.1",
"nunomaduro/termwind": "^1.15|^2.0",
"ralphjsmit/laravel-filament-components": "^2.0",
"socialiteproviders/manager": "^4.3",
"spatie/data-transfer-object": "^3.9.1",
Expand All @@ -36,14 +34,13 @@
"filament/upgrade": "^3.2",
"larastan/larastan": "^2.8",
"laravel/pint": "^1.7",
"nunomaduro/collision": "^7.0",
"orchestra/testbench": "^8.0",
"nunomaduro/collision": "^7.0|^8.1",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^2.3",
"pestphp/pest-plugin-faker": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1.3",
"spatie/invade": "^1.1.1",
"spatie/laravel-package-tools": "^1.16"
},
"autoload": {
Expand Down
17 changes: 17 additions & 0 deletions database/migrations/1_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public function up(): void
$table->rememberToken();
$table->timestamps();
});

Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});

Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}

/**
Expand All @@ -29,5 +44,7 @@ public function up(): void
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
12 changes: 0 additions & 12 deletions routes/stubs/api.php.stub

This file was deleted.

14 changes: 0 additions & 14 deletions routes/stubs/web.php.stub

This file was deleted.

12 changes: 0 additions & 12 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@

namespace MailCarrier\Commands;

use Illuminate\Support\Facades\Validator;
use function Termwind\render;

abstract class Command extends \Illuminate\Console\Command
{
/**
* Validate an incoming input.
*/
protected function validatePrompt(mixed $value, array $rules): ?string
{
return Validator::make(
['field' => $value],
['field' => $rules],
)->errors()->first('field');
}

/**
* Show a success message for a task.
*/
Expand Down
54 changes: 20 additions & 34 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MailCarrier\Commands;

use Composer\Semver\Comparator;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -60,10 +59,10 @@ protected function cleanupLaravel(): void
{
$this->overrideMigrations();
$this->overrideModels();
$this->overrideBootstrap();
$this->overrideRoutes();
$this->overrideProviders();
$this->overrideViews();
$this->overrideHandler();
$this->overrideReadme();
$this->deleteFiles();

Expand All @@ -75,7 +74,10 @@ protected function cleanupLaravel(): void
*/
protected function overrideMigrations(): void
{
@unlink(getcwd() . '/database/migrations/2014_10_12_000000_create_users_table.php');
// Remove existing users table
$this->call('migrate:rollback');

@unlink(getcwd() . '/database/migrations/0001_01_01_000000_create_users_table.php');
@unlink(getcwd() . '/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php');
}

Expand All @@ -87,28 +89,22 @@ protected function overrideModels(): void
copy(__DIR__ . '/../../src/Models/stubs/User.php.stub', getcwd() . '/app/Models/User.php');
}

/**
* Override the default models.
*/
protected function overrideBootstrap(): void
{
copy(__DIR__ . '/../../stubs/bootstrap_app.php.stub', getcwd() . '/bootstrap/app.php');
copy(__DIR__ . '/../../stubs/bootstrap_providers.php.stub', getcwd() . '/bootstrap/providers.php');
}

/**
* Override the default routes.
*/
protected function overrideRoutes(): void
{
$kernelPath = getcwd() . '/app/Console/Kernel.php';
$kernel = file_get_contents($kernelPath);

$kernel = str_replace(
"require base_path('routes/console.php');
",
'',
$kernel
);

file_put_contents($kernelPath, $kernel);

@unlink(getcwd() . '/routes/channels.php');
@unlink(getcwd() . '/routes/console.php');

copy(__DIR__ . '/../../routes/stubs/api.php.stub', getcwd() . '/routes/api.php');
copy(__DIR__ . '/../../routes/stubs/web.php.stub', getcwd() . '/routes/web.php');
@unlink(getcwd() . '/routes/web.php');
}

/**
Expand All @@ -118,7 +114,6 @@ public function overrideProviders(): void
{
copy(__DIR__ . '/../Providers/stubs/AppServiceProvider.php.stub', getcwd() . '/app/Providers/AppServiceProvider.php');
copy(__DIR__ . '/../Providers/stubs/AuthServiceProvider.php.stub', getcwd() . '/app/Providers/AuthServiceProvider.php');
copy(__DIR__ . '/../Providers/stubs/EventServiceProvider.php.stub', getcwd() . '/app/Providers/EventServiceProvider.php');
}

/**
Expand All @@ -134,14 +129,6 @@ protected function overrideViews(): void
copy(__DIR__ . '/../../resources/views/stubs/401.blade.php.stub', $errorsTargetDir . '/401.blade.php');
}

/**
* Override the default models.
*/
protected function overrideHandler(): void
{
copy(__DIR__ . '/../../src/Exceptions/stubs/Handler.php.stub', getcwd() . '/app/Exceptions/Handler.php');
}

/**
* Override the default readme.
*/
Expand All @@ -167,11 +154,6 @@ protected function updateComposerJson(): void
$composerJsonPath = getcwd() . '/composer.json';
$composerJson = file_get_contents($composerJsonPath);

// Set minimum PHP version
if (Comparator::lessThan($this->getComposerValue($composerJson, 'php'), '^8.1')) {
$composerJson = $this->setComposerValue($composerJson, 'php', '^8.1');
}

// Install hook to update MailCarrier
if (!str_contains($composerJson, '"@php artisan mailcarrier:upgrade"')) {
$composerJson = str_replace(
Expand Down Expand Up @@ -227,7 +209,11 @@ protected function publishVendor(): void
'--tag' => 'mailcarrier-assets',
]);

$this->labeledLine('Configuration files and assets copied.');
$this->callSilently('vendor:publish', [
'--tag' => 'sanctum-migrations',
]);

$this->labeledLine('Vendor files copied.');
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Commands/UserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace MailCarrier\Commands;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use MailCarrier\Models\User;
use function Laravel\Prompts\password;
Expand Down Expand Up @@ -46,12 +45,12 @@ protected function getUserData(): array
'email' => text(
'Email address',
required: true,
validate: fn (string $value) => $this->validatePrompt($value, ['email', 'unique:\MailCarrier\Models\User,email']),
validate: ['email' => 'unique:\MailCarrier\Models\User,email'],
),
'password' => password(
'Password',
hint: 'Leave it blank for a random one',
validate: fn (?string $value) => $this->validatePrompt($value, ['nullable', 'min:8']),
validate: ['password' => 'nullable', 'min:8'],
),
];

Expand All @@ -60,9 +59,6 @@ protected function getUserData(): array
$data['password'] = $this->rawRandomPassword = Str::password(16);
}

// Finally encrypt the password
$data['password'] = Hash::make($data['password']);

return $data;
}
}
37 changes: 37 additions & 0 deletions src/Dto/CastableDataTransferObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace MailCarrier\Dto;

use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use MailCarrier\Models\Casts\DataTransferObject as DataTransferObjectCast;
use Spatie\DataTransferObject\DataTransferObject;

/**
* Originally taken from https://github.com/jessarcher/laravel-castable-data-transfer-object.
* Soon or later we're going to remove spatie/data-transfer-object that has been deprecated.
*/
abstract class CastableDataTransferObject extends DataTransferObject implements Arrayable, Castable, Jsonable
{
public static function castUsing(array $arguments)
{
return new DataTransferObjectCast(static::class, $arguments);
}

public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
}

public static function fromJson(string $json, int $options = 0)
{
// @phpstan-ignore-next-line
return new static(json_decode(
$json,
true, // assoc
512, // depth
$options // flags
));
}
}
1 change: 0 additions & 1 deletion src/Dto/ContactDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MailCarrier\Dto;

use JessArcher\CastableDataTransferObject\CastableDataTransferObject;
use MailCarrier\Dto\Validators\Email;
use Spatie\DataTransferObject\Attributes\Strict;

Expand Down
1 change: 0 additions & 1 deletion src/Dto/LogTemplateDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MailCarrier\Dto;

use JessArcher\CastableDataTransferObject\CastableDataTransferObject;
use Spatie\DataTransferObject\Attributes\Strict;

#[Strict]
Expand Down
20 changes: 0 additions & 20 deletions src/Exceptions/stubs/Handler.php.stub

This file was deleted.

15 changes: 15 additions & 0 deletions src/Models/Casts/CastUsingJsonFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace MailCarrier\Models\Casts;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
class CastUsingJsonFlags
{
public function __construct(
public int $encode = 0,
public int $decode = 0,
) {
}
}
Loading