Installation: Add to your Laravel project via Composer:
composer require splash/phpcore
Basic Object Structure: Create a class extending Splash\Core\Models\AbstractObject with IntelParserTrait:
namespace App\Splash\Objects;
use Splash\Core\Models\AbstractObject;
use Splash\Core\Models\Objects\IntelParserTrait;
class Customer extends AbstractObject
{
use IntelParserTrait;
protected static string $name = "Customer";
protected static string $description = "Customer records";
protected static string $ico = "fa-user";
}
First Use Case: Define fields and CRUD operations in traits:
// app/Splash/Objects/Customer/CrudTrait.php
trait CrudTrait
{
public function load(string $id): ?CustomerEntity
{
return Customer::find($id);
}
public function create(): CustomerEntity
{
return new CustomerEntity();
}
}
Object Definition: Extend AbstractObject with traits
class Product extends AbstractObject
{
use IntelParserTrait;
use Product\CrudTrait;
use Product\FieldDefinitionsTrait;
}
Field Management:
buildFields() using fluent APIprotected function buildFields(): void
{
$this->fieldsFactory()->create(SplFields::VARCHAR)
->identifier('sku')
->name('SKU')
->isRequired();
}
CRUD Implementation:
load, create, update, delete)$this->needUpdate() to track changesData Synchronization:
IntelParserTraitSimpleFieldsTrait for basic propertiesLaravel Eloquent: Bridge Splash objects with Eloquent models:
public function load(string $id): ?Product
{
return Product::query()->find($id);
}
Field Validation: Leverage Splash's validation system:
$this->fieldsFactory()->create(SplFields::EMAIL)
->identifier('email')
->isRequired()
->isUnique();
Complex Fields: Use helpers for:
SplFields::PRICESplFields::IMAGESplFields::FILEPagination: Implement objectsList() with metadata:
return [
'items' => $products->toArray(),
'meta' => [
'total' => $products->total(),
'current' => $products->count()
]
];
Field Processing:
protected function getCoreFields(int $key, string $fieldName): void
{
switch ($fieldName) {
case 'name': $this->out[$fieldName] = $this->object->name; break;
case 'price': $this->out[$fieldName] = $this->object->price->value; break;
}
unset($this->in[$key]);
}
Change Tracking:
protected function setCoreFields(string $fieldName, $value): void
{
if ($this->object->{$fieldName} !== $value) {
$this->object->{$fieldName} = $value;
$this->needUpdate();
}
unset($this->in[$fieldName]);
}
List Fields:
protected function getOrderLines(int $key): void
{
$this->out['order_lines'] = $this->object->orderLines->map(function($line) {
return [
'product_id' => $line->product_id,
'quantity' => $line->quantity
];
});
unset($this->in[$key]);
}
Field Processing Order:
unset($this->in[$key]) after processing a fieldChange Detection:
$this->needUpdate() when modifying objects$needed is always falseIdentifier Handling:
getObjectIdentifier() must return null for new objectsType Mismatches:
PRICE vs DOUBLE)Pagination Requirements:
objectsList() must include meta with total and currentEnable Logging:
Splash::log()->setLevel(\Monolog\Logger::DEBUG);
Field Inspection:
// Dump all defined fields
print_r($this->fields());
Change Tracking:
// Check which fields were modified
var_dump($this->changedFields());
Field Identifiers:
user_email) not camelCase (userEmail)Required Fields:
->isRequired() during definitionupdate() if missingList Fields:
isListed() for inclusion in objectsList()SplFields::LIST type for collectionsCustom Field Types:
// Extend base field classes
class CustomPriceField extends SplFields\Price
{
public function validate($value): bool
{
// Custom validation logic
}
}
Object Extensions:
// Add to existing objects
class ExtendedCustomer extends Customer
{
use ExtendedCustomer\AdditionalFieldsTrait;
}
Filter System:
// Implement custom filters
public function applyFilters(array $filters): void
{
if (isset($filters['active_only'])) {
$this->query->where('status', 'active');
}
}
Database Writes:
$needed parameter in update()flush() callsField Processing:
SimpleFieldsTraitPagination:
setMaxResults())Service Provider Binding:
public function register()
{
$this->app->bind('splash.customer', function($app) {
return new \App\Splash\Objects\Customer();
});
}
Query Builder Integration:
public function objectsList(?string $filter = null, array $params = []): array
{
$query = Customer::query();
if ($filter) {
$query->where('name', 'like', "%{$filter}%")
->orWhere('email', 'like', "%{$filter}%");
}
// ... rest of pagination logic
}
Event Listeners:
// Sync after model events
Customer::saved(function($model) {
Splash::sync()->trigger('customer_updated', $model->id);
});
How can I help you explore Laravel packages today?