Skip to content

Commit

Permalink
Laravel 11 (#17)
Browse files Browse the repository at this point in the history
* permission upgrades for l11

* set 8.3

* media library updates

* run on 8.3

* use mysql

* rename driver

* new workflow

* remove artisan commands

* use root account

* test credentials

* add correct doc blocks
  • Loading branch information
nivv authored Apr 10, 2024
1 parent cec685c commit 7973c8b
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpStan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ["8.0", "8.1"]
php-versions: ["8.3"]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
68 changes: 33 additions & 35 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
# GitHub Action for Laravel
name: tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
# GitHub Action for Laravel with MySQL and Redis
name: Testing Laravel with MySQL
on: [push, pull_request]
jobs:
laravel:
name: Laravel (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
name: Laravel (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
BROADCAST_DRIVER: log
DB_CONNECTION: pgsql
DB_HOST: localhost
DB_PASSWORD: secret
DB_USERNAME: homestead
DB_DATABASE: fabriq_testing
DB_USERNAME: root
DB_PASSWORD: password
BROADCAST_DRIVER: log

# Docs: https://docs.github.com/en/actions/using-containerized-services
services:
postgres:
image: postgres:latest
mysql:
image: mysql:latest
env:
POSTGRES_USER: homestead
POSTGRES_PASSWORD: secret
POSTGRES_DB: fabriq_testing
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: fabriq_testing
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.1', '8.0']
php-versions: ['8.3']
steps:
- name: Install ffmpeg
run: sudo apt-get update && sudo apt-get install ffmpeg

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

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: exif, imagick
coverage: pcov #optional
extensions: mbstring, dom, fileinfo, mysql
coverage: xdebug

# Local MySQL service in GitHub hosted environments is disabled by default.
# If you are using it instead of service containers, make sure you start it.
# - name: Start mysql service
# run: sudo systemctl start mysql.service

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
Expand All @@ -58,11 +57,10 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-


- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text --testdox
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
/public/build
.php-cs-fixer.cache
pnpm-lock.yaml
.phpunit.cache
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php": "^8.0",
"illuminate/database": "^8.56|^9.0|^10|^11",
"illuminate/support": "^7.0.5|^8.0|^9.0|^10|^11",
"spatie/laravel-permission": "^4.3|^5.0|^6.0",
"spatie/laravel-permission": "^6.0",
"infab/core": "^2.1",
"spatie/laravel-query-builder": "^3.5|^4.0|^5.0|^6.0",
"spatie/laravel-medialibrary": "^8.2|^9.0|^10.0|^11.0",
Expand All @@ -45,9 +45,9 @@
"laravel/pint": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^9.3.3",
"orchestra/testbench": "^7.0|^8.0",
"nunomaduro/collision": "^5.1|^6.0",
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^9.0",
"nunomaduro/collision": "^5.1|^6.0|^8.0",
"nunomaduro/larastan": "^2.0"
},
"extra": {
Expand All @@ -62,5 +62,11 @@
"php --version && php -d memory_limit=512M ./vendor/bin/phpstan analyse -c phpstan.neon",
"php --version && vendor/bin/phpunit --coverage-text --testdox"
]
},
"repositories": {
"0": {
"type": "vcs",
"url": "https://github.com/KarabinSE/laravel-make-user"
}
}
}
65 changes: 32 additions & 33 deletions database/migrations/2020_12_17_092311_create_permission_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Spatie\Permission\PermissionRegistrar;

class CreatePermissionTables extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
$teams = config('permission.teams');
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';

if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
Expand All @@ -26,7 +25,7 @@ public function up()
}

Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigIncrements('id'); // permission id
$table->string('name'); // For MySQL 8.0 use string('name', 125);
$table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125);
$table->timestamps();
Expand All @@ -35,15 +34,16 @@ public function up()
});

Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) {
$table->bigIncrements('id');
$table->bigIncrements('id'); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
}
$table->string('name'); // For MySQL 8.0 use string('name', 125);
$table->string('guard_name')->default('web'); // For MySQL 8.0 use string('guard_name', 125);
$table->string('guard_name')->nullable(); // For MySQL 8.0 use string('guard_name', 125);
$table->string('display_name')->nullable();
$table->string('description')->nullable();

$table->timestamps();
if ($teams || config('permission.testing')) {
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
Expand All @@ -52,67 +52,68 @@ public function up()
}
});

Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
$table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
$table->unsignedBigInteger($pivotPermission);

$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');

$table->foreign(PermissionRegistrar::$pivotPermission)
->references('id')
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');

$table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
} else {
$table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
}

});

Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole);

$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');

$table->foreign(PermissionRegistrar::$pivotRole)
->references('id')
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');

$table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'],
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
} else {
$table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'],
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
}
});

Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
$table->unsignedBigInteger($pivotPermission);
$table->unsignedBigInteger($pivotRole);

$table->foreign(PermissionRegistrar::$pivotPermission)
->references('id')
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');

$table->foreign(PermissionRegistrar::$pivotRole)
->references('id')
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');

$table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary');
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
});

app('cache')
Expand All @@ -122,10 +123,8 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
$tableNames = config('permission.table_names');

Expand All @@ -139,4 +138,4 @@ public function down()
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function up()
public function down()
{
Schema::table('pages', function (Blueprint $table) {
$table->dropForeign('pages_updated_by_foreign');
$table->dropColumn('updated_by');
});
}
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Ikoncept Test Suite">
<directory>tests</directory>
Expand All @@ -17,4 +12,9 @@
<env name="FFMPEG_PATH" value="ffmpeg"/>
<env name="FFPROBE_PATH" value="ffprobe"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
17 changes: 7 additions & 10 deletions src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Spatie\Image\Manipulations;
use Spatie\Image\Enums\Fit;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Tags\HasTags;

class Image extends Model implements HasMedia
{
use HasFactory, InteractsWithMedia, HasTags;
use HasFactory, HasTags, InteractsWithMedia;

/**
* Morph class.
Expand Down Expand Up @@ -44,14 +44,13 @@ public function imageable(): MorphTo
return $this->morphTo();
}

public function registerMediaConversions(Media $media = null): void
public function registerMediaConversions(?Media $media = null): void
{
$this->addMediaConversion('thumb')
->nonQueued()
->width(360)
->crop(Manipulations::CROP_CENTER, 480, 320)
->format(config('fabriq.enable_webp') ? 'webp' : 'jpg')
->quality(80);
->nonQueued()
->fit(Fit::Crop, 480, 320)
->format(config('fabriq.enable_webp') ? 'webp' : 'jpg')
->quality(80);

if (config('fabriq.enable_webp')) {
$this->addMediaConversion('webp')
Expand All @@ -69,9 +68,7 @@ public function mediaImages(): MorphMany
/**
* Search for an image.
*
* @param Builder $query
* @param string|null $search
* @return Builder
*/
public function scopeSearch(Builder $query, $search): Builder
{
Expand Down
Loading

0 comments on commit 7973c8b

Please sign in to comment.