| @@ 10-35 (lines=26) @@ | ||
| 7 | use Illuminate\Database\QueryException; |
|
| 8 | use Throwable; |
|
| 9 | ||
| 10 | class MissingColumnSolutionProvider implements HasSolutionsForThrowable |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * See https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html#error_er_bad_field_error. |
|
| 14 | */ |
|
| 15 | const MYSQL_BAD_FIELD_CODE = '42S22'; |
|
| 16 | ||
| 17 | public function canSolve(Throwable $throwable): bool |
|
| 18 | { |
|
| 19 | if (! $throwable instanceof QueryException) { |
|
| 20 | return false; |
|
| 21 | } |
|
| 22 | ||
| 23 | return $this->isBadTableErrorCode($throwable->getCode()); |
|
| 24 | } |
|
| 25 | ||
| 26 | protected function isBadTableErrorCode($code): bool |
|
| 27 | { |
|
| 28 | return $code === static::MYSQL_BAD_FIELD_CODE; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function getSolutions(Throwable $throwable): array |
|
| 32 | { |
|
| 33 | return [new RunMigrationsSolution('A column was not found')]; |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 10-35 (lines=26) @@ | ||
| 7 | use Illuminate\Database\QueryException; |
|
| 8 | use Throwable; |
|
| 9 | ||
| 10 | class TableNotFoundSolutionProvider implements HasSolutionsForThrowable |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * See https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html#error_er_bad_table_error. |
|
| 14 | */ |
|
| 15 | const MYSQL_BAD_TABLE_CODE = '42S02'; |
|
| 16 | ||
| 17 | public function canSolve(Throwable $throwable): bool |
|
| 18 | { |
|
| 19 | if (! $throwable instanceof QueryException) { |
|
| 20 | return false; |
|
| 21 | } |
|
| 22 | ||
| 23 | return $this->isBadTableErrorCode($throwable->getCode()); |
|
| 24 | } |
|
| 25 | ||
| 26 | protected function isBadTableErrorCode($code): bool |
|
| 27 | { |
|
| 28 | return $code === static::MYSQL_BAD_TABLE_CODE; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function getSolutions(Throwable $throwable): array |
|
| 32 | { |
|
| 33 | return [new RunMigrationsSolution('A table was not found')]; |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||