Skip to content

Commit 997023b

Browse files
committed
docs: use Config\Auth::$tables
1 parent a0dffd1 commit 997023b

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

docs/customization/adding_attributes_to_users.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,39 @@ And write code to add/drop columns.
1919

2020
namespace App\Database\Migrations;
2121

22+
use CodeIgniter\Database\Forge;
2223
use CodeIgniter\Database\Migration;
2324

2425
class AddMobileNumberToUsers extends Migration
2526
{
27+
/**
28+
* @var string[]
29+
*/
30+
private array $tables;
31+
32+
public function __construct(?Forge $forge = null)
33+
{
34+
parent::__construct($forge);
35+
36+
/** @var \Config\Auth $authConfig */
37+
$authConfig = config('Auth');
38+
$this->tables = $authConfig->tables;
39+
}
40+
2641
public function up()
2742
{
2843
$fields = [
2944
'mobile_number' => ['type' => 'VARCHAR', 'constraint' => '20', 'null' => true],
3045
];
31-
$this->forge->addColumn('users', $fields);
46+
$this->forge->addColumn($this->tables['users'], $fields);
3247
}
3348

3449
public function down()
3550
{
3651
$fields = [
3752
'mobile_number',
3853
];
39-
$this->forge->dropColumn('users', $fields);
54+
$this->forge->dropColumn($this->tables['users'], $fields);
4055
}
4156
}
4257
```

0 commit comments

Comments
 (0)