You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/database/files.md
+98-1Lines changed: 98 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ This example will add a `created_at` column to the `posts` table with the curren
137
137
138
138
## Multiple DB connections <Badge>New</Badge>
139
139
140
-
Leaf MVC supports multiple database connections via the `database.php` configuration file. By default, Leaf uses the `default` connection for all database operations. However, if you want to use a different connection for a specific table, you can specify the connection in the schema file using the `connection` key. Here's an example:
140
+
Leaf MVC supports multiple database connections via the `config/database.php` configuration file. By default, Leaf uses the `default` connection for all database operations. However, if you want to use a different connection for a specific table, you can specify the connection in the schema file using the `connection` key. Here's an example:
141
141
142
142
```yml:no-line-numbers [posts.yml]
143
143
connection: postsDbConnection
@@ -147,6 +147,103 @@ columns:
147
147
body: text
148
148
```
149
149
150
+
::: details Example Multi-Database Setup
151
+
152
+
Here is an example of how you might set up multiple database connections in your `config/database.php` file:
This example defines three PostgreSQL connections: `pgsql`, `analytics`, and `imports`, and an SQLite connection. You can then specify which database you want to run a migration on by setting the `connection` property as shown above.
244
+
245
+
:::
246
+
150
247
## Schema columns
151
248
152
249
In a schema file, you can define the columns of your table under the `columns` key. The key is the column name and the value is the type of column or an array of properties for the column:
Copy file name to clipboardExpand all lines: src/docs/database/models.md
+99-2Lines changed: 99 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,9 +256,9 @@ class Flight extends Model
256
256
}
257
257
```
258
258
259
-
## Database Connection
259
+
## Multiple Database Connections
260
260
261
-
By default, all Leaf models will use the default database connection configured for your application. If you would like to specify a different connection for the model, use the `$connection` property:
261
+
By default, all Leaf models will use the default database connection configured for your application. If you would like to specify a different database connection for the model, you need to set that up first in your `config/database.php` configuration file. Once you have done that, you may specify the connection name in your model like this:
262
262
263
263
```php
264
264
class Flight extends Model
@@ -272,6 +272,103 @@ class Flight extends Model
272
272
}
273
273
```
274
274
275
+
::: details Example Multi-Database Setup
276
+
277
+
Here is an example of how you might set up multiple database connections in your `config/database.php` file:
This example defines three PostgreSQL connections: `pgsql`, `analytics`, and `imports`, and an SQLite connection. You can then specify which connection a model should use by setting the `$connection` property in the model class as shown above.
369
+
370
+
:::
371
+
275
372
## Default Attribute Values
276
373
277
374
If you would like to define the default values for some of your model's attributes, you may define an $attributes property on your model:
0 commit comments