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

Accessible Laravel Package

antares/accessible

View on GitHub
Deep Wiki
Context7

How to manage collections

Accessible provides 3 annotations to give to make properties behave as collections:

  • ListBehavior: The property behaves as a simple list.
  • SetBehavior: The property behaves as a set (every item is unique).
  • MapBehavior: The property behaves as a key => value array.

These annotations add two methods to the class:

  • addX: Add an item to the collection.
  • removeX: Remove an item from the collection.

The 'X' in these methods is the name of an item in the collection. The item name may be defined in the annotation by setting its itemName property. By default, the item name will be the singular version of the property (determined using Doctrine's Inflector library).

Here is an example:

use Accessible\Annotation\ListBehavior;
use Accessible\Annotation\MapBehavior;
use Accessible\Annotation\SetBehavior;

class Student
{
  /**
   * This property is initialized as an empty array and can be modified with addCourse() and removeCourse().
   *
   * [@Access](https://github.com/Access)({Access:GET})
   * [@SetBehavior](https://github.com/SetBehavior)
   * [@Initialize](https://github.com/Initialize)({})
   */
  private $courses;

  /**
   * This property is initialized as an empty array and can be modified with addTask() and removeTask().
   *
   * [@Access](https://github.com/Access)({Access:GET})
   * [@ListBehavior](https://github.com/ListBehavior)(itemName="task")
   * [@Initialize](https://github.com/Initialize)({})
   */
  private $homework;

  /**
   * This property is initialized as an empty array and can be modified with addNote() and removeNote().
   *
   * [@Access](https://github.com/Access)({Access:GET})
   * [@MapBehavior](https://github.com/MapBehavior)()
   * [@Initialize](https://github.com/Initialize)({})
   */
  private $notes;
}

$student = new Student();

$course = new Course();
$student->addCourse($course);
$student->getCourses(); // -> [$course]
$student->removeCourse($course);

$task = new Task();
$student->addTask($task);
$student->getHomework(); // -> [$task]
$student->removeTask($task);

$note = new Note();
$student->addNote("someNote", $note);
$student->getNotes(); // -> ["someNote" => $note]
$student->removeNote("someNote");

Note that the properties are initialized as empty arrays, but they can also be initialized as instances of Doctrine collections via [@InitializeObject](https://github.com/InitializeObject).

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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle