@@ -32,13 +32,19 @@ public static function forModel(string $modelClass): self
3232 return new self (model ($ modelClass )->getTableDefinition ()->name );
3333 }
3434
35+ /**
36+ * Adds a primary key column to the table. MySQL and SQLite use an auto-incrementing `INTEGER` column, and PostgreSQL uses `SERIAL`.
37+ */
3538 public function primary (string $ name = 'id ' ): self
3639 {
3740 $ this ->statements [] = new PrimaryKeyStatement ($ name );
3841
3942 return $ this ;
4043 }
4144
45+ /**
46+ * Adds a foreign key relationship to another table.
47+ */
4248 public function belongsTo (
4349 string $ local ,
4450 string $ foreign ,
@@ -60,6 +66,9 @@ public function belongsTo(
6066 return $ this ;
6167 }
6268
69+ /**
70+ * Adds a `TEXT` column to the table.
71+ */
6372 public function text (string $ name , bool $ nullable = false , ?string $ default = null ): self
6473 {
6574 $ this ->statements [] = new TextStatement (
@@ -71,6 +80,9 @@ public function text(string $name, bool $nullable = false, ?string $default = nu
7180 return $ this ;
7281 }
7382
83+ /**
84+ * Adds a `VARCHAR` column to the table.
85+ */
7486 public function varchar (string $ name , int $ length = 255 , bool $ nullable = false , ?string $ default = null ): self
7587 {
7688 $ this ->statements [] = new VarcharStatement (
@@ -83,6 +95,9 @@ public function varchar(string $name, int $length = 255, bool $nullable = false,
8395 return $ this ;
8496 }
8597
98+ /**
99+ * Adds a `VARCHAR` column to the table.
100+ */
86101 public function string (string $ name , int $ length = 255 , bool $ nullable = false , ?string $ default = null ): self
87102 {
88103 return $ this ->varchar (
@@ -93,6 +108,9 @@ public function string(string $name, int $length = 255, bool $nullable = false,
93108 );
94109 }
95110
111+ /**
112+ * Adds a `CHAR` column to the table.
113+ */
96114 public function char (string $ name , bool $ nullable = false , ?string $ default = null ): self
97115 {
98116 $ this ->statements [] = new CharStatement (
@@ -104,6 +122,9 @@ public function char(string $name, bool $nullable = false, ?string $default = nu
104122 return $ this ;
105123 }
106124
125+ /**
126+ * Adds an `INTEGER` column to the table.
127+ */
107128 public function integer (string $ name , bool $ unsigned = false , bool $ nullable = false , ?int $ default = null ): self
108129 {
109130 $ this ->statements [] = new IntegerStatement (
@@ -116,6 +137,9 @@ public function integer(string $name, bool $unsigned = false, bool $nullable = f
116137 return $ this ;
117138 }
118139
140+ /**
141+ * Adds a `FLOAT` column to the table.
142+ */
119143 public function float (string $ name , bool $ nullable = false , ?float $ default = null ): self
120144 {
121145 $ this ->statements [] = new FloatStatement (
@@ -127,6 +151,9 @@ public function float(string $name, bool $nullable = false, ?float $default = nu
127151 return $ this ;
128152 }
129153
154+ /**
155+ * Adds a datetime column to the table. Uses `DATETIME` for MySQL/SQLite and `TIMESTAMP` for PostgreSQL.
156+ */
130157 public function datetime (string $ name , bool $ nullable = false , ?string $ default = null ): self
131158 {
132159 $ this ->statements [] = new DatetimeStatement (
@@ -138,6 +165,9 @@ public function datetime(string $name, bool $nullable = false, ?string $default
138165 return $ this ;
139166 }
140167
168+ /**
169+ * Adds a `DATE` column to the table.
170+ */
141171 public function date (string $ name , bool $ nullable = false , ?string $ default = null ): self
142172 {
143173 $ this ->statements [] = new DateStatement (
@@ -149,6 +179,9 @@ public function date(string $name, bool $nullable = false, ?string $default = nu
149179 return $ this ;
150180 }
151181
182+ /**
183+ * Adds a `BOOLEAN` column to the table.
184+ */
152185 public function boolean (string $ name , bool $ nullable = false , ?bool $ default = null ): self
153186 {
154187 $ this ->statements [] = new BooleanStatement (
@@ -160,6 +193,9 @@ public function boolean(string $name, bool $nullable = false, ?bool $default = n
160193 return $ this ;
161194 }
162195
196+ /**
197+ * Adds a JSON column to the table. Uses `JSON` for MySQL, `TEXT` for SQLite, and `JSONB` for PostgreSQL.
198+ */
163199 public function json (string $ name , bool $ nullable = false , ?string $ default = null ): self
164200 {
165201 $ this ->statements [] = new JsonStatement (
@@ -171,6 +207,9 @@ public function json(string $name, bool $nullable = false, ?string $default = nu
171207 return $ this ;
172208 }
173209
210+ /**
211+ * Alias for `json()` method. Adds a JSON column for storing serializable objects.
212+ */
174213 public function object (string $ name , bool $ nullable = false , ?string $ default = null ): self
175214 {
176215 $ this ->statements [] = new JsonStatement (
@@ -182,6 +221,9 @@ public function object(string $name, bool $nullable = false, ?string $default =
182221 return $ this ;
183222 }
184223
224+ /**
225+ * Adds a JSON column for storing arrays. The default value is automatically JSON-encoded, as opposed to `json` and `object`.
226+ */
185227 public function array (string $ name , bool $ nullable = false , array $ default = []): self
186228 {
187229 $ this ->statements [] = new JsonStatement (
@@ -193,6 +235,9 @@ public function array(string $name, bool $nullable = false, array $default = [])
193235 return $ this ;
194236 }
195237
238+ /**
239+ * Adds an enum column to the table. Uses the `ENUM` type for MySQL, falls back to `TEXT` for SQLite, and uses a custom enum type for PostgreSQL.
240+ */
196241 public function enum (string $ name , string $ enumClass , bool $ nullable = false , null |UnitEnum |BackedEnum $ default = null ): self
197242 {
198243 $ this ->statements [] = new EnumStatement (
@@ -205,6 +250,9 @@ enumClass: $enumClass,
205250 return $ this ;
206251 }
207252
253+ /**
254+ * Adds a `SET` column to the table. Only supported in MySQL.
255+ */
208256 public function set (string $ name , array $ values , bool $ nullable = false , ?string $ default = null ): self
209257 {
210258 $ this ->statements [] = new SetStatement (
@@ -217,6 +265,9 @@ public function set(string $name, array $values, bool $nullable = false, ?string
217265 return $ this ;
218266 }
219267
268+ /**
269+ * Adds a unique constraint on the specified columns.
270+ */
220271 public function unique (string ...$ columns ): self
221272 {
222273 $ this ->trailingStatements [] = new UniqueStatement (
@@ -227,6 +278,9 @@ public function unique(string ...$columns): self
227278 return $ this ;
228279 }
229280
281+ /**
282+ * Adds an index on the specified columns.
283+ */
230284 public function index (string ...$ columns ): self
231285 {
232286 $ this ->trailingStatements [] = new IndexStatement (
@@ -237,6 +291,9 @@ public function index(string ...$columns): self
237291 return $ this ;
238292 }
239293
294+ /**
295+ * Adds a raw SQL statement to the table definition.
296+ */
240297 public function raw (string $ statement ): self
241298 {
242299 $ this ->statements [] = new RawStatement ($ statement );
0 commit comments