Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Cycle Orm Adapter Laravel Package

wayofdev/laravel-cycle-orm-adapter

View on GitHub
Deep Wiki
Context7

import {Callout} from "nextra-theme-docs"; import ExternalLink from "../../components/external-link";

Defining Entities

To get started with CycleORM entities in Laravel, you typically place your entity classes in the app/Entities directory. This is a departure from the conventional app/Models directory used by Eloquent.

Here's a basic example of a Post entity in CycleORM:

<?php

declare(strict_types=1);

namespace App\Entities;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\ORM\Entity\Behavior\Uuid\Uuid7;
use Ramsey\Uuid\UuidInterface;

#[Entity]
#[Uuid7(field: 'id')]
class Post
{
    #[Column(type: 'uuid', primary: true)]
    public UuidInterface $id;

    #[Column(type: "string")]
    private string $title;

    #[Column(type: "text")]
    private string $content;

    public function __construct(string $title, string $content)
    {
        $this->title = $title;
        $this->content = $content;
    }

    public function id(): UuidInterface
    {
        return $this->id;
    }

    public function title(): string
    {
        return $this->title;
    }

    public function content(): string
    {
        return $this->content;
    }
}

By default, the laravel-cycle-orm-adapter is configured to scan the app/Entities directory for entities. However, you can customize this behavior by modifying the tokenizer section in the config/cycle.php configuration file. Here's how you can adjust it:

return [
    'tokenizer' => [
        'directories' => [
            app_path('Entities'), // Directs CycleORM to scan this directory for entities
        ],
        // Additional configuration...
    ],
];

For projects adopting Domain-Driven Design (DDD) principles, it's common to place entities within a domain-specific layer, such as Domain/Post, rather than a single directory. This approach not only organizes your codebase around your business domain but also enhances the scalability and maintainability of your application.

Adjusting the config/cycle.php for a DDD structure might look like this:

return [
    'tokenizer' => [
        'directories' => [
            __DIR__ . '/../src/Domain', // Load entities from all Domains
            __DIR__ . '/../vendor/wayofdev/laravel-webhook-client/src/Entities', // Load entities from vendor directory
        ],
        // Additional configuration...
    ],
];

This setup ensures that your Laravel application benefits from the clear separation of concerns provided by the Data Mapper pattern, with CycleORM efficiently managing the persistence of your domain entities.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity