22
33use Bavix \Wallet \Models \Transaction ;
44use Illuminate \Database \Migrations \Migration ;
5+ use Illuminate \Database \MySqlConnection ;
56use Illuminate \Database \Schema \Blueprint ;
7+ use Illuminate \Support \Facades \DB ;
68use Illuminate \Support \Facades \Schema ;
9+ use Illuminate \Database \Schema \ColumnDefinition ;
710
811class CreateTransactionsTable extends Migration
912{
@@ -19,7 +22,7 @@ public function up(): void
1922 $ table ->enum ('type ' , ['deposit ' , 'withdraw ' ])->index ();
2023 $ table ->bigInteger ('amount ' );
2124 $ table ->boolean ('confirmed ' );
22- $ table ->json ('meta ' )->nullable ();
25+ $ this ->json ($ table , 'meta ' )->nullable ();
2326 $ table ->uuid ('uuid ' )->unique ();
2427 $ table ->timestamps ();
2528
@@ -29,6 +32,27 @@ public function up(): void
2932 });
3033 }
3134
35+ /**
36+ * @param Blueprint $table
37+ * @param string $column
38+ * @return ColumnDefinition
39+ */
40+ public function json (Blueprint $ table , string $ column ): ColumnDefinition
41+ {
42+ $ conn = DB ::connection ();
43+ if ($ conn instanceof MySqlConnection) {
44+ $ pdo = $ conn ->getPdo ();
45+ try {
46+ $ sql = 'SELECT JSON_EXTRACT( \'[10, 20, [30, 40]] \', \'$[1] \'); ' ;
47+ $ pdo ->exec ($ sql );
48+ } catch (\Throwable $ throwable ) {
49+ return $ table ->text ($ column );
50+ }
51+ }
52+
53+ return $ table ->json ($ column );
54+ }
55+
3256 /**
3357 * @return string
3458 */
0 commit comments