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
Database and ORM are <strong>not built into the kernel</strong>. They're capabilities you install when you need them. Install a database capability like <code>ForgeDatabaseSQL</code> or an ORM capability like <code>ForgeSqlOrm</code>.
851
+
Database and ORM are <strong>not built into the kernel</strong>. They're capabilities you install when you need them. Install a database capability like <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeDatabaseSQL</code> or an ORM capability like <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeSqlOrm</code>.
852
852
</p>
853
853
<pclass="text-gray-600 mb-4">
854
-
<strong>Note:</strong> The examples below assume you've installed a database/ORM capability. The kernel itself doesn't include these features.
854
+
Forge provides <strong>three ways to work with data</strong>:
<li><strong>Raw SQL Queries:</strong> Use <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code> or <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code> directly, even without installing an ORM capability. This is available through the kernel's database contracts.</li>
858
+
<li><strong>Query Builder:</strong> Use the fluent query builder interface for type-safe database operations.</li>
859
+
<li><strong>ORM:</strong> Use the ForgeSqlOrm capability for attribute-based models and relationships.</li>
860
+
</ol>
861
+
<pclass="text-gray-600 mb-4">
862
+
<strong>Note:</strong> The ORM examples below assume you've installed the <codeclass="bg-gray-100 px-2 py-1 rounded">ForgeSqlOrm</code> capability. Raw queries and query builder are available through the kernel's database contracts.
You can use raw SQL queries without installing any ORM capability. The kernel provides <codeclass="bg-gray-100 px-2 py-1 rounded">QueryBuilderInterface</code> and <codeclass="bg-gray-100 px-2 py-1 rounded">DatabaseConnectionInterface</code> for direct database access. This is how migrations work internally.
<li><codeclass="bg-gray-100 px-2 py-1 rounded">core: true</code> — Module won't be auto-loaded. You must wire it manually in your bootstrap or service providers.</li>
999
+
<li><codeclass="bg-gray-100 px-2 py-1 rounded">isCli: true</code> — Module won't be loaded in web context. Only loaded when running CLI commands.</li>
The <codeclass="bg-gray-100 px-2 py-1 rounded">#[ConfigDefaults]</code> attribute allows you to define default configuration values directly in your module class, eliminating the need for a separate <codeclass="bg-gray-100 px-2 py-1 rounded">config/</code> folder and config file.
1056
+
</p>
1057
+
<pclass="text-gray-600 mb-4">
1058
+
You can still override these defaults by creating a config file in <codeclass="bg-gray-100 px-2 py-1 rounded">/config/</code> (e.g., <codeclass="bg-gray-100 px-2 py-1 rounded">config/my_module.php</code>). When loading configuration in your module, you need to explicitly define that the config can be overridden from the <codeclass="bg-gray-100 px-2 py-1 rounded">/config/</code> directory.
<h3class="text-lg font-semibold mb-3 text-gray-900">Post-Install and Post-Uninstall Hooks</h3>
1080
+
<pclass="text-gray-600 mb-4">
1081
+
Use <codeclass="bg-gray-100 px-2 py-1 rounded">#[PostInstall]</code> and <codeclass="bg-gray-100 px-2 py-1 rounded">#[PostUninstall]</code> attributes to automatically run CLI commands after a module is installed or removed. This is useful for running migrations, linking assets, seeding data, or performing other setup/cleanup tasks.
// Commands run automatically after install/uninstall
1093
+
}</code></pre>
1094
+
</div>
1095
+
<pclass="text-gray-600 mb-4">
1096
+
You can specify multiple <codeclass="bg-gray-100 px-2 py-1 rounded">#[PostInstall]</code> or <codeclass="bg-gray-100 px-2 py-1 rounded">#[PostUninstall]</code> attributes. Commands are executed in the order they appear on the class.
0 commit comments