thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.81k stars 2.67k forks source link

getDoctrineColumn does not exist in Laravel 11 #5876

Closed mjasnaashari closed 2 months ago

mjasnaashari commented 3 months ago

Laravel version

11

PHP version

8.2

Voyager version

1.8.x-dev

Database

MySQL 8.0

Description

I'm experiencing an issue with the Voyager package when trying to run migrations in Laravel 11. The error message I'm receiving is:

Method Illuminate\Database\MySqlConnection::getDoctrineColumn does not exist.

This is because the getDoctrineColumn method no longer exists in Laravel 11, as it was removed in favor of using the getSchemaBuilder method to retrieve column information.

I've tried updating the doctrine/dbal package to the latest version compatible with Laravel 11, but the issue persists. I've also tried modifying the relevant code in the migration file to use the getSchemaBuilder method instead of getDoctrineColumn, but the issue still occurs.

I've searched the Voyager package's GitHub issues and found a similar issue (https://github.com/reliese/laravel/issues/273) that was resolved by updating the schema to support the default schema on Postgres and Laravel 11 support on MySQL. However, the changes mentioned in that issue have not been applied to the Voyager package yet.

Steps to reproduce

  1. Install Laravel 11 and the Voyager package.
  2. Run php artisan migrate to run the migrations.
  3. Observe the error message.

Expected behavior

The migrations should run successfully without any errors.

Screenshots

No response

Additional context

I believe the issue can be resolved by updating the schema in the Voyager package to use the getSchemaBuilder method instead of getDoctrineColumn. This change should be applied to the relevant migration files in the package.

Here's how the relevant code in the migration file can be modified to use the getSchemaBuilder method:

  1. Open the migration file that contains the error(vendor/tcg/voyager/migrations/2017_11_26_015000_create_user_roles_table.php)
  2. Locate the line that uses getDoctrineColumn(line 17 for me!)
  3. Replace the line with the following code:
    -- $type = DB::connection()->getDoctrineColumn(DB::getTablePrefix().'users', 'id')->getType()->getName();
    ++ $type = DB::connection()->getSchemaBuilder()->getColumnType('users', 'id');
  4. Save the file.
  5. After making this change, run the migrations again using the following command:
    php artisan migrate

    This should resolve the issue without the need to modify the vendor files.

bhargavraviya commented 3 months ago

@MohammadJavad-AsnaAshari

Please check this code https://laravel.com/docs/11.x/upgrade#get-column-types

  $type = Schema::getColumnType(DB::getTablePrefix().'users','id');
bobbyiliev commented 2 months ago

Thanks for brining that up. I've implemented this on the 1.8 branch.

It is still not fully compatible with Laravel 11 though as the TCG\Voyager\Database\Types; still uses the deprecated Doctrine DBAL.