Skip to content

Commit

Permalink
Merge branch '1.8' into 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev authored Oct 14, 2024
2 parents f88499f + 3b0c42d commit a7fae8c
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Select PHP version
uses: shivammathur/setup-php@master
with:
php-version: '8.1'
php-version: '8.2'
extensions: mbstring, pdo_sqlite, fileinfo, gd
coverage: pcov

Expand All @@ -33,7 +33,7 @@ jobs:

# Install PHP dependencies
- name: Install Composer dependencies
run: composer require "illuminate/support:9.*" --no-ansi
run: composer require "illuminate/support:11.*" --no-ansi

# Install NPM dependencies
- name: Install Dependencies
Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0, 8.1, 8.2]
laravel: ['8.*', '9.*', '10.*']
php: [8.1, 8.2, 8.3]
laravel: ['11.*']
exclude:
- php: 8.2
laravel: 8.*
- php: 7.3
laravel: 9.*
- php: 7.4
laravel: 9.*
- php: 8.2
laravel: 9.*
- php: 7.3
laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 8.0
laravel: 10.*
- php: 8.1
laravel: 11.*

name: 'PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }}'

Expand Down Expand Up @@ -77,4 +65,3 @@ jobs:
# Run phpunit tests
- name: Run tests
run: ./vendor/bin/phpunit --no-coverage

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ Laravel Admin & BREAD System (Browse, Read, Edit, Add, & Delete), supporting Lar

> Want to use Laravel 6 or 7? Use [Voyager 1.5](https://github.com/the-control-group/voyager/tree/1.5)
> Want to use Laravel 8 or 9? Use [Voyager 1.6](https://github.com/the-control-group/voyager/tree/1.6)
> Want to use Laravel 10? Use [Voyager 1.7](https://github.com/the-control-group/voyager/tree/1.7)
## Installation Steps

> [!WARNING]
> As of Laravel 11 the Doctrine DBAL package has been removed from Laravel. This currently breaks the Voyager Database Manager. We are working on a fix for this, but in the meantime, you can just use the Laravel Database migrations to manage your database instead.
### 1. Require the Package

After creating your new Laravel application you can include the Voyager package with the following command:
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
}
],
"require": {
"php": "^7.3|^7.4|^8.0|^8.1|^8.2",
"illuminate/support": "~8.0|~9.0|~10.0",
"php": "^8.2|^8.3",
"illuminate/support": "11.*",
"intervention/image": "^2.7",
"doctrine/dbal": "^3.1|^3.5",
"laravel/ui": ">=1.0",
"arrilot/laravel-widgets": "^3.7",
"league/flysystem": "~1.1|~2.0|~3.0",
Expand All @@ -31,7 +30,7 @@
"require-dev": {
"phpunit/phpcov": ">=6.0",
"phpunit/phpunit": ">=8.0",
"laravel/framework": "~8.0|~9.0|~10.0",
"laravel/framework": "~8.0|~9.0|~10.0|~11.0",
"orchestra/testbench": ">=6.0",
"laravel/browser-kit-testing": ">=6.1.0",
"orchestra/testbench-browser-kit": ">=4.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/bread/formfields/date-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
}
```

The date & timestamp input field is where you can input a date. In the JSON above you can specify the `format` value of the output of the date. It allows you to display a formatted `date` in browse and read views, using Carbon's `formatLocalized()` method
The date & timestamp input field is where you can input a date. In the JSON above you can specify the `format` value of the output of the date. It allows you to display a formatted `date` in browse and read views, using Carbon's `format()` method
3 changes: 2 additions & 1 deletion docs/core-concepts/database-manager.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Database Manager

> Warning: As of Laravel 11 the Doctrine DBAL package has been removed from Laravel. This currently breaks the Voyager Database Manager. We are working on a fix for this, but in the meantime, you can just use the Laravel Database migrations to manage your database instead.
Voyager has some awesome database tools which allow you to Add/Edit/Delete or view current database tables. The other cool part of Voyager is that you can add BREAD or \(Browse, Read, Edit, Add, & Delete\) functionality to any of your tables.

![](../.gitbook/assets/database-manager.png)
Expand All @@ -13,4 +15,3 @@ If you click the table name you can view the current schema. Additionally you ca
You may also choose to Add BREAD \(Browse, Read, Edit, Add, & Delete\) for any of your database tables. Once a table already has BREAD you may choose to edit the current BREAD or Delete the BREAD for that table.

Read on further about the BREAD builder in the next section.

2 changes: 1 addition & 1 deletion migrations/2017_11_26_015000_create_user_roles_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateUserRolesTable extends Migration
public function up()
{
Schema::create('user_roles', function (Blueprint $table) {
$type = DB::connection()->getDoctrineColumn(DB::getTablePrefix().'users', 'id')->getType()->getName();
$type = DB::connection()->getSchemaBuilder()->getColumnType('users', 'id');
if ($type == 'bigint') {
$table->bigInteger('user_id')->unsigned()->index();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class AlterPostNullableFieldsTable extends Migration
*/
public function up()
{
$platform = \DB::getDoctrineSchemaManager()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

Schema::table('posts', function (Blueprint $table) {
$table->text('excerpt')->nullable()->change();
$table->text('meta_description')->nullable()->change();
Expand All @@ -31,9 +28,9 @@ public function up()
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->text('excerpt')->change();
$table->text('meta_description')->change();
$table->text('meta_keywords')->change();
$table->text('excerpt')->nullable(false)->change();
$table->text('meta_description')->nullable(false)->change();
$table->text('meta_keywords')->nullable(false)->change();
});
}
}
2 changes: 1 addition & 1 deletion resources/views/bread/browse.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

@elseif($row->type == 'date' || $row->type == 'timestamp')
@if ( property_exists($row->details, 'format') && !is_null($data->{$row->field}) )
{{ \Carbon\Carbon::parse($data->{$row->field})->formatLocalized($row->details->format) }}
{{ \Carbon\Carbon::parse($data->{$row->field})->format('Y-m-d H:i:s') }}
@else
{{ $data->{$row->field} }}
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/bread/read.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
@endif
@elseif($row->type == 'date' || $row->type == 'timestamp')
@if ( property_exists($row->details, 'format') && !is_null($dataTypeContent->{$row->field}) )
{{ \Carbon\Carbon::parse($dataTypeContent->{$row->field})->formatLocalized($row->details->format) }}
{{ \Carbon\Carbon::parse($dataTypeContent->{$row->field})->format('Y-m-d H:i:s') }}
@else
{{ $dataTypeContent->{$row->field} }}
@endif
Expand Down
159 changes: 89 additions & 70 deletions src/Database/Schema/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@

namespace TCG\Voyager\Database\Schema;

use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Table as DoctrineTable;
use Illuminate\Support\Facades\DB;
use TCG\Voyager\Database\Types\Type;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Collection;

abstract class SchemaManager
{
// todo: trim parameters

public static function __callStatic($method, $args)
{
return static::manager()->$method(...$args);
}

public static function manager()
{
return DB::connection()->getDoctrineSchemaManager();
return DB::connection();
}

public static function getDatabaseConnection()
{
return DB::connection()->getDoctrineConnection();
return DB::connection();
}

public static function tableExists($table)
Expand All @@ -32,112 +30,133 @@ public static function tableExists($table)
$table = [$table];
}

return static::manager()->tablesExist($table);
return Schema::hasTable($table[0]);
}

public static function listTables()
{
$tables = [];
$tableNames = Schema::getConnection()->getSchemaBuilder()->getTables();

foreach (static::manager()->listTableNames() as $tableName) {
foreach ($tableNames as $tableName) {
$tables[$tableName] = static::listTableDetails($tableName);
}

return $tables;
}

/**
* @param string $tableName
*
* @return \TCG\Voyager\Database\Schema\Table
*/
public static function listTableDetails($tableName)
{
$columns = static::manager()->listTableColumns($tableName);

$foreignKeys = [];
if (static::manager()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$foreignKeys = static::manager()->listTableForeignKeys($tableName);
}
$columns = Schema::getColumnListing($tableName);
$columnDetails = collect($columns)->mapWithKeys(function ($column) use ($tableName) {
return [$column => static::getColumnDetails($tableName, $column)];
});

$indexes = static::manager()->listTableIndexes($tableName);
$indexes = static::getTableIndexes($tableName);
$foreignKeys = static::getTableForeignKeys($tableName);

return new Table($tableName, $columns, $indexes, [], $foreignKeys, []);
return new Table($tableName, $columnDetails->toArray(), $indexes, [], $foreignKeys, []);
}

/**
* Describes given table.
*
* @param string $tableName
*
* @return \Illuminate\Support\Collection
*/
public static function describeTable($tableName)
{
Type::registerCustomPlatformTypes();
$columns = Schema::getColumnListing($tableName);

$table = static::listTableDetails($tableName);
return collect($columns)->map(function ($column) use ($tableName) {
$columnDetails = static::getColumnDetails($tableName, $column);
$indexes = static::getColumnIndexes($tableName, $column);

return collect($table->columns)->map(function ($column) use ($table) {
$columnArr = Column::toArray($column);

$columnArr['field'] = $columnArr['name'];
$columnArr['type'] = $columnArr['type']['name'];

// Set the indexes and key
$columnArr['indexes'] = [];
$columnArr['key'] = null;
if ($columnArr['indexes'] = $table->getColumnsIndexes($columnArr['name'], true)) {
// Convert indexes to Array
foreach ($columnArr['indexes'] as $name => $index) {
$columnArr['indexes'][$name] = Index::toArray($index);
}

// If there are multiple indexes for the column
// the Key will be one with highest priority
$indexType = array_values($columnArr['indexes'])[0]['type'];
$columnArr['key'] = substr($indexType, 0, 3);
if (!empty($indexes) && isset($indexes[1])) {
$indexes = [$indexes[1]];
}

return $columnArr;
return [
'field' => $column,
'type' => $columnDetails['type'],
'null' => $columnDetails['nullable'],
'key' => !empty($indexes) ? substr($indexes[0]['type'], 0, 3) : null,
'default' => $columnDetails['default'],
'extra' => $columnDetails['auto_increment'] ? 'auto_increment' : '',
'indexes' => $indexes,
];
});
}

public static function listTableColumnNames($tableName)
{
Type::registerCustomPlatformTypes();

$columnNames = [];
return Schema::getColumnListing($tableName);
}

foreach (static::manager()->listTableColumns($tableName) as $column) {
$columnNames[] = $column->getName();
public static function createTable($table)
{
if ($table instanceof Blueprint) {
Schema::create($table->getTable(), function (Blueprint $blueprint) use ($table) {
foreach ($table->getColumns() as $column) {
$blueprint->addColumn(
$column->getType()->getName(),
$column->getName(),
$column->toArray()
);
}
});
} else {
throw new \InvalidArgumentException('Table must be an instance of Blueprint');
}

return $columnNames;
}

public static function createTable($table)
protected static function getColumnDetails($table, $column)
{
if (!($table instanceof DoctrineTable)) {
$table = Table::make($table);
$schema = Schema::getConnection()->getSchemaBuilder();
$columnType = $schema->getColumnType($table, $column);
$columnDefinition = $schema->getColumns($table);

$columnInfo = collect($columnDefinition)->firstWhere('name', $column);

if (!$columnInfo) {
throw new \InvalidArgumentException("Column '$column' not found in table '$table'.");
}

static::manager()->createTable($table);
return [
'type' => $columnType,
'nullable' => !($columnInfo['nullable'] ?? false),
'default' => $columnInfo['default'] ?? null,
'auto_increment' => ($columnInfo['auto_increment'] ?? false),
];
}

public static function getDoctrineTable($table)
protected static function getTableIndexes($table)
{
$table = trim($table);
return DB::getSchemaBuilder()->getIndexes($table);
}

if (!static::tableExists($table)) {
throw SchemaException::tableDoesNotExist($table);
}
protected static function getColumnIndexes($table, $column)
{
$tableIndexes = static::getTableIndexes($table);
return collect($tableIndexes)->filter(function ($index) use ($column) {
return in_array($column, $index['columns']);
})->toArray();
}

return static::manager()->listTableDetails($table);
protected static function getTableForeignKeys($table)
{
return DB::getSchemaBuilder()->getForeignKeys($table);
}

public static function getDoctrineColumn($table, $column)
public static function listTableNames()
{
return static::getDoctrineTable($table)->getColumn($column);
$connection = Schema::getConnection();

// Check if the connection supports the getTables method
if (method_exists($connection->getSchemaBuilder(), 'getTables')) {
$tables = $connection->getSchemaBuilder()->getTables();
return collect($tables)->pluck('name')->values()->all();
}

// Fallback method if getTables is not available
$tables = $connection->getDoctrineSchemaManager()->listTableNames();

// Filter out tables that should be excluded (like migrations)
$excludedTables = ['migrations', 'failed_jobs', 'password_resets'];
return array_values(array_diff($tables, $excludedTables));
}
}
Loading

0 comments on commit a7fae8c

Please sign in to comment.