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

laravel migration: column preg_match can be null $columns->sql #17

Open
eelco2k opened this issue Jan 20, 2025 · 0 comments
Open

laravel migration: column preg_match can be null $columns->sql #17

eelco2k opened this issue Jan 20, 2025 · 0 comments

Comments

@eelco2k
Copy link

eelco2k commented Jan 20, 2025

in some edge cases where you check for a column and the column does not exists it returns an error:

Schema::hasColumn("carts", 'order_id');
 ErrorException 

  Attempt to read property "sql" on null

  at vendor/turso/libsql-laravel/src/Database/LibsqlSchemaBuilder.php:89
     85▕ 
     86▕         $columns = $this->connection->selectOne("SELECT sql FROM sqlite_master WHERE type='table' AND name='{$table}'");
     87▕ 
     88▕         $pattern = '/(?:\(|,)\s*[\'"`]?([a-zA-Z_][a-zA-Z0-9_]*)[\'"`]?\s+[a-zA-Z]+/i';
  ➜  89▕         preg_match_all($pattern, $columns->sql, $matches);
     90▕         $columnMatches = $matches[1] ?? [];
     91▕ 
     92▕         $delctypes = stdClassToArray($data);
     93▕         foreach ($delctypes as $key => $value) {

      +28 vendor frames 

  29  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

should check if is not null ??

if (!empty($columns->sql)) {
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant