Installation
composer require apie/common
Ensure your Laravel project meets the package's PHP version requirements (check composer.json of the package).
First Use Case: Creating Objects
use Apie\Common\Actions\CreateObjectAction;
$action = new CreateObjectAction($persistenceLayer);
$result = $action->execute($rawData, $resourceName);
$rawData as an array or object representing the resource attributes.Where to Look First
src/Actions/ for available actions like GetListAction, RunAction./tests/ for usage examples and edge cases.Resource CRUD with Actions
// Create
$createAction = new CreateObjectAction($persistence);
$user = $createAction->execute(['name' => 'John'], 'users');
// List with Filtering
$listAction = new GetListAction($persistence);
$users = $listAction->execute(['active' => true], 'users');
execute() for filtering (e.g., ['status' => 'published']).RPC-style Operations
$runAction = new RunAction($service);
$result = $runAction->execute('calculateTotal', ['items' => $cartItems]);
Integration with Laravel Services
// Bind actions to Laravel container
$app->bind(CreateObjectAction::class, function ($app) {
return new CreateObjectAction($app->make(PersistenceLayer::class));
});
Eloquent Integration:
$persistence = new EloquentPersistence(User::class);
$createAction = new CreateObjectAction($persistence);
Apie\Persistence\PersistenceInterface for custom ORMs.API Resource Mapping:
Combine with apie/rest-api to auto-generate API endpoints for actions:
// Example: Map GetListAction to a REST endpoint
$router->get('/users', function () {
$action = app()->make(GetListAction::class);
return $action->execute([], 'users');
});
Persistence Layer Assumptions
Apie\Persistence\PersistenceInterface.Data Validation
ValidatesRequests or FormRequest before passing data to actions.Monorepo Dependency Confusion
composer.json:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/apie-lib/apie-lib-monorepo"
}
]
$action->setLogger(app()->make(\Psr\Log\LoggerInterface::class));
ResourceNotFoundException: Verify $resourceName matches your persistence layer’s entity names.MethodNotFoundException: Check the service/class passed to RunAction for the method name.Custom Actions
Extend Apie\Common\Actions\AbstractAction to create reusable logic:
class ExportAction extends AbstractAction {
public function execute(array $filters, string $resource) {
// Custom logic
}
}
Middleware for Actions Wrap actions in middleware for auth/validation:
$action = new CreateObjectAction($persistence);
$action->setMiddleware([new AuthMiddleware(), new ValidateMiddleware()]);
Event Dispatching Trigger events after action execution:
$action->onSuccess(function ($result) {
event(new ObjectCreated($result));
});
How can I help you explore Laravel packages today?