Installation Steps
Installation Steps
Follow these straightforward steps to set up and start using Data Forge in your Laravel projects.
Prerequisites
Before installation, ensure that your system meets the following requirements:
- PHP 8.0 or higher
- Composer (Dependency Manager for PHP)
- Laravel 8.x or higher
Recommended:
- A compatible relational database such as MySQL.
Step 1: Install Data Forge
Add the Data Forge package to your Laravel project using Composer:
composer require astra-techno/data-forge
Step 2: Register the Service Provider (If Necessary)
For Laravel 8.x and above, service providers are automatically discovered. If you're using an older version, manually register the DataForge service provider in the providers
array of config/app.php
:
'providers' => [
astra\DataForge\DataForgeServiceProvider::class,
];
Step 3: Directory Structure Setup
Ensure the following directory structure exists in your Laravel application:
App/DataForge/Sql/
For SQL classes that define reusable queries.App/DataForge/Entity/
For Entity classes that encapsulate business logic.App/DataForge/Task/
For Task classes that handle custom actions and workflows.
Step 4: Create Custom Classes (Optional)
Data Forge provides default base classes for SQL, Entity, and Task components. Extend these classes to define your custom logic.
Example SQL Class
namespace App\DataForge\Sql;
use DataForge\Sql;
class Invoice extends Sql
{
public function list(array &$data)
{
return $this->query('InvoiceList')
->select('list', 'i.id AS invoiceId, i.date, i.amount, c.name AS customerName')
->select('item', 'i.*')
->select('entity', 'i.id AS invoiceId, i.date, i.amount, i.customer_id, c.name AS customerName')
->select('total', 'COUNT(DISTINCT i.id)')
->from('invoices AS i')
->join('customers AS c', 'i.customer_id = c.id')
->filter('i.status = 1')
->filterOptional('c.name LIKE {%request.keyword%}')
->group('i.id')
->sort('{request.sort ?? i.date}', '{request.order ?? DESC}');
}
}
Example Entity Class
namespace App\DataForge\Entity;
use DataForge\Entity;
class Invoice extends Entity
{
public function init(int $id)
{
return Sql('Invoice:list', ['select' => 'entity', 'id' => $id])->fetchRow();
}
}
Step 5: Verify Installation
After setup, test your installation by accessing the following sample API endpoints:
Fetch a List of Invoices
Retrieve the first 20 invoices along with the total count:
GET /api/list/Invoice/list
Fetch an Invoice Entity
Retrieve the base attributes of an invoice entity:
GET /api/entity/Invoice/12345
Troubleshooting
Common Issues:
Dependency Errors:
Ensure that all required dependencies (PHP, Composer, Laravel) are installed and compatible.Directory Structure Missing:
Verify that theApp/DataForge/
directory and its subfolders are properly set up.Incorrect API Response:
Check your SQL or Entity class logic for potential issues.
For further help, visit our FAQ or contact support.
Next Steps
With the installation complete, proceed to the Core Concepts section to learn how to define and use SQL, Entity, and Task classes in your project.
Start building scalable, high-performance applications with Data Forge today!