Weave 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.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo