### Install EAV Dashboard via Composer Source: https://github.com/sunel/eav/blob/master/docs/master/dashboard.md Uses Composer to add the sunel/eav-dashboard package to a Laravel project. No additional dependencies are required beyond Composer itself. Run this command in the project root to install the package. ```bash composer require sunel/eav-dashboard ``` -------------------------------- ### Publish Dashboard assets with Artisan Source: https://github.com/sunel/eav/blob/master/docs/master/dashboard.md Runs the eav-dash:publish Artisan command to copy the dashboard's public assets into the Laravel application's public directory. The optional --clean flag removes previously published assets before copying new ones. ```bash php artisan eav-dash:publish ``` ```bash php artisan eav-dash:publish --clean ``` -------------------------------- ### Get Available Backend and Frontend Types via REST API Source: https://context7.com/sunel/eav/llms.txt Retrieves configuration options for attribute creation using GET requests to the API. It fetches available backend storage types and frontend input types separately. Both responses are JSON arrays containing strings representing the available types. ```bash # Get backend storage types curl -X GET "http://api.example.com/backend/types" \ -H "Accept: application/json" ``` ```json { "data": [ "boolean", "date", "dateTime", "double", "integer", "text", "string" ] } ``` ```bash # Get frontend input types curl -X GET "http://api.example.com/frontend/types" \ -H "Accept: application/json" ``` ```json { "data": [ "text", "select", "number", "textarea", "integer", "date", "time", "dateTime", "boolean" ] } ``` -------------------------------- ### GET /entities Source: https://context7.com/sunel/eav/llms.txt Retrieve a list of all configured entities within the system. Supports pagination for large result sets. ```APIDOC ## List Entities via REST API ### Description Retrieve all configured entities. This endpoint supports pagination. ### Method GET ### Endpoint `/entities` ### Parameters #### Query Parameters - **page[size]** (integer) - Optional - Number of entities to return per page. - **page[number]** (integer) - Optional - The page number to retrieve. ### Request Example ```bash curl -X GET "http://api.example.com/entities?page[size]=10&page[number]=1" \ -H "Accept: application/vnd.api+json" ``` ### Response #### Success Response (200) - **data** (array) - An array of entity objects. - **type** (string) - The type of the resource, always 'entities'. - **id** (string) - The unique identifier for the entity. - **attributes** (object) - Contains the entity's properties. - **code** (string) - The entity's code. - **class** (string) - The PHP class associated with the entity. - **table** (string) - The database table name for the entity. - **is_flat_enabled** (boolean) - Indicates if flat data is enabled for the entity. - **meta** (object) - Metadata about the pagination. - **page** (object) - Pagination details. - **current-page** (integer) - The current page number. - **per-page** (integer) - The number of items per page. - **from** (integer) - The starting item index for the current page. - **to** (integer) - The ending item index for the current page. - **total** (integer) - The total number of items across all pages. - **last-page** (integer) - The last page number. #### Response Example ```json { "data": [ { "type": "entities", "id": "1", "attributes": { "code": "product", "class": "App\\Product", "table": "products", "is_flat_enabled": false } } ], "meta": { "page": { "current-page": 1, "per-page": 10, "from": 1, "to": 1, "total": 1, "last-page": 1 } } } ``` ``` -------------------------------- ### GET /frontend/types Source: https://context7.com/sunel/eav/llms.txt Provides the supported frontend input types for attribute creation. ```APIDOC ## GET /frontend/types\n\n### Description\nProvides the supported frontend input types for attribute creation.\n\n### Method\nGET\n\n### Endpoint\n/frontend/types\n\n### Parameters\n_No parameters._\n\n### Request Example\n```bash\ncurl -X GET \"http://api.example.com/frontend/types\" -H \"Accept: application/json\"\n```\n\n### Response\n#### Success Response (200)\n- **data** (array) - List of frontend input type strings.\n\n### Response Example\n```json\n{\n \"data\": [\n \"text\",\n \"select\",\n \"number\",\n \"textarea\",\n \"integer\",\n \"date\",\n \"time\",\n \"dateTime\",\n \"boolean\"\n ]\n}\n``` ``` -------------------------------- ### Define Dashboard access gate in Laravel Source: https://github.com/sunel/eav/blob/master/docs/master/dashboard.md Implements a gate named viewEavDash to control who can view the EAV Dashboard in non‑local environments. The example restricts access to a specific email address, but can be customized as needed. ```php /** * Register the Dashboard gate. * * This gate determines who can access Dashboard in non-local environments. * * @return void */ protected function gate() { Gate::define('viewEavDash', function ($user) { return in_array($user->email, [ 'sunelbe@gmail.com', ]); }); } ``` -------------------------------- ### Register API Service Provider in Laravel config Source: https://github.com/sunel/eav/blob/master/docs/master/dashboard.md Adds the EAV API service provider to the Laravel application's provider list in config/app.php. This step is required for the dashboard to function correctly. ```php 'providers' => [ ..., Eav\Api\ServiceProvider::class, ] ``` -------------------------------- ### Get Facets for Filtering (PHP) Source: https://context7.com/sunel/eav/llms.txt This code snippet demonstrates how to retrieve facets with counts for filtering using the EAV module. It shows how to get facets for a specific product and includes an example of how to iterate through the results and display them. Dependencies: App\Product. Input: Filters. Output: Array of facet options with counts. ```php use App\Product; // Get facets with counts $facets = Product::whereAttribute('in_stock', true) ->whereAttribute('price', '>', 100) ->getFacets(true); // Returns structure like: // [ // 'color' => [ // ['label' => 'Red', 'value' => 1, 'count' => 15], // ['label' => 'Blue', 'value' => 2, 'count' => 23], // ['label' => 'Black', 'value' => 4, 'count' => 31], // ], // 'in_stock' => [ // ['label' => 'Yes', 'value' => 1, 'count' => 52], // ['label' => 'No', 'value' => 0, 'count' => 17], // ] // ] // Use for building filter UI foreach ($facets['color'] as $option) { echo "{$option['label']} ({$option['count']})\n"; } ``` -------------------------------- ### GET /backend/types Source: https://context7.com/sunel/eav/llms.txt Retrieves the list of supported backend storage types that can be used when defining attributes. ```APIDOC ## GET /backend/types\n\n### Description\nReturns the collection of backend storage types that can be used when defining attributes.\n\n### Method\nGET\n\n### Endpoint\n/backend/types\n\n### Parameters\n_No parameters._\n\n### Request Example\n```bash\ncurl -X GET \"http://api.example.com/backend/types\" -H \"Accept: application/json\"\n```\n\n### Response\n#### Success Response (200)\n- **data** (array) - List of backend type strings.\n\n### Response Example\n```json\n{\n \"data\": [\n \"boolean\",\n \"date\",\n \"dateTime\",\n \"double\",\n \"integer\",\n \"text\",\n \"string\"\n ]\n}\n``` ``` -------------------------------- ### Perform Custom EAV Query in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/snippet.md This PHP snippet shows how to build a custom query using an EAV structure. It demonstrates finding an attribute, joining it to a product query with a left join, and selecting a specific attribute column. It assumes the existence of `Products` and `Eav\Attribute` models. ```php $products = Products::select('*'); $attribute = Eav\Attribute::findByCode('inventory', 'product'); $attribute->setEntity($products->baseEntity()); // Joining the attribute to the query, by default it will use inner join. // In this case we need a left join. $attribute->addAttributeJoin($products->getQuery(), 'left'); $attributeColumn = $attribute->getRawSelectColumn(); // inventory_attr.value $products->selectRaw("COUNT({$attributeColumn}) as total"); $products->get(); ``` -------------------------------- ### List Entities via REST API (Bash) Source: https://context7.com/sunel/eav/llms.txt This snippet demonstrates retrieving all configured entities using a REST API request with curl. It specifies the HTTP method, URL, and headers for a GET request. Input: API endpoint, optional parameters for pagination. Output: JSON response containing a list of entities. ```bash curl -X GET "http://api.example.com/entities?page[size]=10&page[number]=1" -H "Accept: application/vnd.api+json" ``` -------------------------------- ### Retrieve Attributes for an Attribute Set (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-set.md Illustrates how to fetch the attributes that belong to a specific attribute set. This involves first getting the attribute sets for an entity and then accessing the 'attributes' relationship on the first set. ```php $sets = $entity->attributeSet; $sets->first()->attributes; ``` -------------------------------- ### Querying with EAV Attributes Source: https://context7.com/sunel/eav/llms.txt Provides examples of querying entities based on their dynamic EAV attributes. This functionality extends the Eloquent query builder to allow filtering, ordering, and selecting attributes as if they were native columns. It supports simple `WHERE` clauses, multiple conditions, `OR` conditions, and nested query structures. ```php use App\Product; // Simple where clause on attribute $products = Product::whereAttribute('in_stock', true) ->get(['*', 'sku', 'name', 'price']); // Multiple conditions $laptops = Product::whereAttribute('name', 'like', '%Laptop%') ->whereAttribute('price', '<=', 1500) ->whereAttribute('in_stock', true) ->orderByAttribute('price', 'desc') ->get(['*', 'name', 'price']); // Select all attributes with attr.* $allData = Product::whereAttribute('sku', 'LAPTOP-XPS-15') ->get(['attr.*']); // Complex queries with OR conditions $results = Product::whereAttribute('name', 'like', 'Dell%') ->orWhereAttribute('name', 'like', 'HP%') ->whereBetweenAttribute('price', [500, 2000]) ->get(['*', 'name', 'price', 'sku']); // Nested conditions $filtered = Product::whereAttribute('in_stock', true) ->whereAttribute(function ($query) { $query->whereAttribute('price', '<', 1000) ->orWhereAttribute('name', 'like', '%Sale%'); }) ->orderByAttribute('price', 'asc') ->get(['*', 'name', 'price']); ``` -------------------------------- ### GET /entities/{entity_code}/attributes Source: https://context7.com/sunel/eav/llms.txt List all attributes for a specific entity, with support for filtering and pagination. ```APIDOC ## Get Entity Attributes via REST API ### Description List all attributes for a specific entity with filtering and pagination support. ### Method GET ### Endpoint `/entities/{entity_code}/attributes` ### Parameters #### Path Parameters - **entity_code** (string) - Required - The code of the entity whose attributes are to be retrieved. #### Query Parameters - **filter[search]** (string) - Optional - A search term to filter attributes by name or code. - **page[size]** (integer) - Optional - Number of attributes to return per page. - **page[number]** (integer) - Optional - The page number to retrieve. ### Request Example ```bash curl -X GET "http://api.example.com/entities/product/attributes?filter[search]=name&page[size]=25" \ -H "Accept: application/vnd.api+json" ``` ### Response #### Success Response (200) - **data** (array) - An array of attribute objects. - **type** (string) - The type of the resource, always 'attributes'. - **id** (string) - The unique identifier for the attribute. - **attributes** (object) - Contains the attribute's properties. - **code** (string) - The attribute's code. - **label** (string) - The frontend label for the attribute. - **type** (string) - The frontend input type (e.g., 'text', 'select', 'number'). - **backend_type** (string) - The database storage type (e.g., 'string', 'integer'). - **is_required** (boolean) - Indicates if the attribute is mandatory. - **is_filterable** (boolean) - Indicates if the attribute can be used for filtering. - **is_searchable** (boolean) - Indicates if the attribute can be used for searching. - **default_value** (string|null) - The default value for the attribute. - **meta** (object) - Metadata about the pagination. - **page** (object) - Pagination details. - **current-page** (integer) - The current page number. - **per-page** (integer) - The number of items per page. - **total** (integer) - The total number of items. #### Response Example ```json { "data": [ { "type": "attributes", "id": "2", "attributes": { "code": "name", "label": "Product Name", "type": "text", "backend_type": "string", "is_required": true, "is_filterable": false, "is_searchable": true, "default_value": null } } ], "meta": { "page": { "current-page": 1, "per-page": 25, "total": 1 } } } ``` ``` -------------------------------- ### Get Facets for Filtering (PHP SDK) Source: https://context7.com/sunel/eav/llms.txt This section explains how to retrieve filterable attribute options along with their counts for faceted search using the EAV PHP SDK. This is useful for building dynamic filter UIs. ```APIDOC ## Get Facets for Filtering ### Description Retrieve filterable attribute options with counts for faceted search using the EAV PHP SDK. ### Method N/A (SDK Usage) ### Endpoint N/A (SDK Usage) ### Parameters N/A (SDK Usage) ### Request Example ```php use App\Product; // Get facets with counts $facets = Product::whereAttribute('in_stock', true) ->whereAttribute('price', '>', 100) ->getFacets(true); // Returns structure like: // [ // 'color' => [ // ['label' => 'Red', 'value' => 1, 'count' => 15], // ['label' => 'Blue', 'value' => 2, 'count' => 23], // ['label' => 'Black', 'value' => 4, 'count' => 31], // ], // 'in_stock' => [ // ['label' => 'Yes', 'value' => 1, 'count' => 52], // ['label' => 'No', 'value' => 0, 'count' => 17], // ] // ] // Use for building filter UI foreach ($facets['color'] as $option) { echo "{$option['label']} ({$option['count']})\n"; } ``` ### Response N/A (SDK Usage) ``` -------------------------------- ### Create Attribute Migration with Inline Attributes in Bash Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute.md Generates a migration for attributes using comma-separated code:type pairs for quick setup with few attributes. Requires entity_code as input; outputs migration file needing potential updates for types like backend_type. Limitations: best for small sets; run php artisan migrate after. ```bash php artisan eav:make:attribute product -A name:string,search:boolean,description:text ``` -------------------------------- ### Retrieve Single Attribute in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute.md Gets a specific attribute by code and entity code. Depends on EavAttribute model; inputs attribute_code and entity_code strings; outputs single Attribute instance or null if not found. Useful for targeted access; no additional dependencies beyond EAV setup. ```php $sizeAttribute = Eav\Attribute::findByCode('size', 'product') ``` -------------------------------- ### Build Advanced Custom Queries with Attribute Joins in PHP Source: https://context7.com/sunel/eav/llms.txt Constructs complex queries by manually joining and manipulating attribute data. This PHP example demonstrates how to select all product data, find a specific attribute, add a left join for that attribute, and use its raw column name in aggregate functions. It requires the 'Attribute' model. ```php use App\Product; use Eav\Attribute; // Build custom query with manual attribute joins $products = Product::select('*'); $attribute = Attribute::findByCode('in_stock', 'product'); $attribute->setEntity($products->baseEntity()); // Add left join instead of default inner join $attribute->addAttributeJoin($products->getQuery(), 'left'); // Get raw column name for calculations $attributeColumn = $attribute->getRawSelectColumn(); // in_stock_attr.value // Use in aggregate functions $products->selectRaw("COUNT({$attributeColumn}) as available_count"); $products->whereNotNull($attributeColumn); $result = $products->first(); echo "Available products: " . $result->available_count; ``` -------------------------------- ### Selecting Data from EAV Models in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/queries.md This functionality allows retrieving data from EAV models by selecting specific fields, all attributes, or combinations from entity and attribute tables. It depends on Eloquent models like Products and supports operators like all(), get(), and select(). Inputs are column selectors (e.g., ['attr.*'], ['upc','color']); outputs are query results. Limitation: Full attribute retrieval can be expensive, so selective queries are recommended. ```php use App\Products; $product = Products::all(); ``` ```php $product = Products::all(['attr.*']); ``` ```php $product = Products::all(['upc','color']); ``` ```php $product = Products::all(['*', 'upc', 'color']); ``` ```php $product = Products::all(['id', 'upc', 'color']); ``` ```php Products::whereAttribute('upc', 'SHNDUU451885') ->get(['color']) ``` ```php Products::whereAttribute('upc', 'SHNDUU451885') ->select(['attr.*']) ->get() ``` -------------------------------- ### Remove EAV Attribute Options (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-options.md Removes specific options from an EAV attribute. This example demonstrates removing the 'Small' option for the 'size' attribute of the 'product' entity. ```php Eav\AttributeOption::remove(Eav\Attribute::findByCode('size', 'product'), [ 's' => 'Small' ]); ``` -------------------------------- ### Get Entity Attributes via REST API (Bash) Source: https://context7.com/sunel/eav/llms.txt This snippet demonstrates retrieving attributes for a specific entity using a REST API request with curl. It includes filtering by attribute name and pagination parameters. Input: API endpoint, entity code, filter parameters, pagination parameters. Output: JSON response containing a list of attributes. ```bash curl -X GET "http://api.example.com/entities/product/attributes?filter[search]=name&page[size]=25" -H "Accept: application/vnd.api+json" ``` -------------------------------- ### Retrieve Groups from Set in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-group.md Shows how to retrieve attribute groups associated with an entity's attribute set. The example demonstrates finding an entity by code, accessing its attribute sets, and retrieving groups from the first set. This follows Laravel's relationship chaining pattern. ```php $entity = Eav\Entity::findByCode('code'); $sets = $entity->attributeSet; $groups = $sets->first()->attributeGroup; ``` -------------------------------- ### Filter by Null Attribute Value (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/queries.md The `whereNullAttribute` and `orWhereNullAttribute` methods identify records where a specified attribute's value is `NULL`. For queries involving table joins, attributes must be explicitly included in the `get` call. ```php $product = Products::whereNullAttribute('search') ->orWhereNullAttribute('color') ->get(['*', 'search', 'color']); ``` -------------------------------- ### Retrieve Attributes from Group in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-group.md Illustrates retrieving attributes belonging to a specific group through the hasManyThrough relationship. Builds upon the previous example by accessing the attributes property on a group instance. This demonstrates lazy loading of nested relationships. ```php $entity = Eav\Entity::findByCode('code'); $sets = $entity->attributeSet; $groups = $sets->first()->attributeGroup; $groups->first()->attributes ``` -------------------------------- ### Filter by Not Null Attribute Value (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/queries.md The `whereNotNullAttribute` and `orWhereNotNullAttribute` methods return records where a specified attribute's value is not `NULL`. Similar to `whereNullAttribute`, explicit attribute listing in `get` is required for join table scenarios. ```php $product = Products::whereNotNullAttribute('search') ->whereNotNullAttribute('color') ->get(['*', 'search', 'color']); ``` -------------------------------- ### EAV Select Source Options Source: https://github.com/sunel/eav/blob/master/docs/master/configuration.md Defines the available sources for populating 'select' input fields in the EAV package. Includes database options and specific class references. ```php 'selectSources' => [ 'database', \Eav\Attribute\Source\Boolean::class, ], ``` -------------------------------- ### Generate Entity Migration and Model (Bash) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/entity.md Creates both the migration file for the entity's main table and entity data type table, along with the corresponding Eloquent model. It requires an entity code and an entity class name as arguments. ```bash $ php artisan eav:make:entity [entity_code] [entity_class_name] ``` -------------------------------- ### Create Attribute with Select Options (PHP SDK) Source: https://context7.com/sunel/eav/llms.txt This section demonstrates how to create a new attribute with predefined select options using the EAV PHP SDK. It covers attribute creation, adding options, and using the attribute in a model. ```APIDOC ## Create Attribute with Select Options ### Description Define attributes with predefined option values using the EAV PHP SDK. ### Method N/A (SDK Usage) ### Endpoint N/A (SDK Usage) ### Parameters N/A (SDK Usage) ### Request Example ```php use Eav\Attribute; use Eav\AttributeOption; // Create select attribute $attribute = Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'color', 'backend_type' => 'integer', 'frontend_type' => 'select', 'frontend_label' => 'Color', 'is_filterable' => true, ]); // Add options AttributeOption::add($attribute, [ ['label' => 'Red', 'value' => 1], ['label' => 'Blue', 'value' => 2], ['label' => 'Green', 'value' => 3], ['label' => 'Black', 'value' => 4], ]); // Use in model $product = Product::find(1); $product->color = 1; // Red $product->save(); // Query by option $redProducts = Product::whereAttribute('color', 1)->get(['*', 'name', 'color']); ``` ### Response N/A (SDK Usage) ``` -------------------------------- ### All Supported EAV Field Types Source: https://github.com/sunel/eav/blob/master/docs/master/configuration.md Lists all currently supported database field types for the EAV package. This comprehensive list includes various data types for different storage needs. ```php 'bigInteger', 'binary', 'boolean', 'char', 'date', 'dateTime', 'dateTimeTz', 'decimal', 'double', 'float', 'geometry', 'geometryCollection', 'integer', 'ipAddress', 'json', 'jsonb', 'lineString', 'longText', 'macAddress', 'mediumInteger', 'mediumText', 'multiLineString', 'multiPoint', 'multiPolygon', 'point', 'polygon', 'smallInteger', 'string', 'text', 'time', 'timeTz', 'timestamp', 'timestampTz', 'tinyInteger', 'unsignedBigInteger', 'unsignedInteger', 'unsignedMediumInteger','unsignedSmallInteger', 'unsignedTinyInteger', 'uuid', 'year', ``` -------------------------------- ### Create New Attribute Set (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-set.md Demonstrates how to create a new Attribute Set for a specific entity. It requires finding the entity first and then creating the set with a name and the entity's ID. ```php $entity = Eav\Entity::findByCode('code'); Eav\AttributeSet::create([ 'attribute_set_name' => 'kids_clothing', 'entity_id' => $entity->entity_id, ]); ``` -------------------------------- ### Publish EAV Configuration Source: https://github.com/sunel/eav/blob/master/docs/master/configuration.md Command to publish the EAV package configuration file to your project. This makes the configuration file editable. ```bash php artisan vendor:publish --tag="eav.config" ``` -------------------------------- ### Create EAV Model and Migration Source: https://github.com/sunel/eav/blob/master/docs/master/model.md Artisan commands to generate a new EAV model and its corresponding migration file. The `-e product` flag specifies the entity name. ```bash php artisan eav:make:model -e product $ php artisan eav:make:entity product \App\Products ``` -------------------------------- ### EAV API Middleware Configuration Source: https://github.com/sunel/eav/blob/master/docs/master/configuration.md Configures the middleware stack to be applied when using the EAV package's API. Allows customization of request handling for API endpoints. ```php 'api' => [ 'middleware' => [ 'web' ] ], ``` -------------------------------- ### PHP: Build and Execute Faceted Search Query Source: https://github.com/sunel/eav/blob/master/docs/master/facet.md This snippet demonstrates how to build a faceted search query using a query builder, applying multiple attribute filters and selecting specific columns. It then retrieves the search results and the associated facets. ```php $search = Products::whereAttribute('upc', 'like', 'SHNDUU%') ->whereAttribute('color', 'like', 'Green%') ->whereAttribute('size', '=', 's') ->select(['*','color']); $result = $search->get(); $facets = $search->getFacets(); ``` -------------------------------- ### Compile and Use Flat Table for Performance in PHP Source: https://context7.com/sunel/eav/llms.txt Optimizes query performance by compiling a denormalized flat table from the EAV structure. This involves running artisan commands to compile, migrate, and activate the flat table. Once activated, queries to the entity model automatically use the flat table, and you can manually enable or disable its usage. ```bash # Compile flat table migration from EAV structure php artisan eav:compile:entity product # Run the generated migration php artisan migrate # Activate flat table usage php artisan eav:flat:entity:activate product ``` ```php // After activation, queries automatically use flat table use App\Product; // This now queries products_flat instead of joining EAV tables $products = Product::whereAttribute('price', '>', 1000) ->orderByAttribute('name') ->get(['*', 'name', 'price', 'sku']); // Manually enable/disable flat tables $product = new Product(); $product->setUseFlat(false); // Use EAV tables $product->setUseFlat(true); // Use flat table if ($product->canUseFlat()) { echo "Flat table is available"; } ``` -------------------------------- ### Generate Entity Model (Bash) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/entity.md Generates the Eloquent model file for a given entity code. This command requires the entity class name and the entity code as parameters. ```bash $ php artisan eav:make:model [entity_class_name] -e [entity_code] ``` -------------------------------- ### Create Flat Table - Artisan Command Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/flat-table.md Compiles EAV entity attributes into a flat table schema. Requires PHP Artisan and an existing entity code. This command collects all attributes and builds the database schema for improved query performance. ```bash $ php artisan eav:compile:entity [entity_code] ``` -------------------------------- ### Supported EAV Element Types Source: https://github.com/sunel/eav/blob/master/docs/master/configuration.md Specifies the list of HTML element types supported by the EAV package for front-end rendering. These map to different input controls. ```php 'elementTypes' => [ 'text', 'select', 'number', 'textarea', 'integer', 'date', 'time', 'dateTime', 'boolean' ], ``` -------------------------------- ### Create Attribute Migration from CSV Source in Bash Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute.md Creates a migration by reading attribute details from a CSV file, ideal for many attributes. Inputs entity_code and CSV path with headers; outputs populated migration file for further edits. Supports sample CSV format; maps to entity automatically. ```bash php artisan eav:make:attribute product -S storage/attribute.csv ``` -------------------------------- ### Accessing Entity Data (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/entity.md Demonstrates how to retrieve an entity instance by its ID and access its base entity information. This involves finding the model instance and then calling the baseEntity() method. ```php $product = Products::find(1); # instance of Eav\Entity $product->baseEntity(); ``` -------------------------------- ### Create Attribute Set via REST API (Bash) Source: https://context7.com/sunel/eav/llms.txt This snippet demonstrates creating a new attribute set for an entity using a REST API request with curl. It uses a POST request and specifies the name of the attribute set in JSON format. Input: API endpoint, entity code, JSON data representing the new attribute set. Output: JSON response containing the created attribute set. ```bash curl -X POST "http://api.example.com/entities/product/set" -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" -d '{ "data": { "type": "attribute-sets", "attributes": { "name": "Electronics" } } }' ``` -------------------------------- ### Create Entity Configuration and Model Source: https://context7.com/sunel/eav/llms.txt Generates the necessary configuration and Eloquent model for a new entity using an Artisan command. This sets up the foundation for managing attributes of a specific entity type. It requires the entity name and the full namespace of the corresponding model. ```bash php artisan eav:make:entity product \App\Product php artisan migrate ``` ```php 'Small', 'm' => 'Medium', 'l' => 'Large', 'xl' => 'Xtra Large', ]); ``` -------------------------------- ### Retrieve Attribute Sets for an Entity (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-set.md Shows how to retrieve all the attribute sets associated with a particular entity. This is done by accessing the 'attributeSet' relationship on the entity object. ```php $entity = Eav\Entity::findByCode('code'); $sets = $entity->attributeSet; ``` -------------------------------- ### Create Attribute via REST API (Bash) Source: https://context7.com/sunel/eav/llms.txt This snippet demonstrates creating a new attribute for an entity using a REST API request with curl. It uses a POST request with JSON data to specify the attribute's details. Input: API endpoint, entity code, JSON data representing the new attribute. Output: JSON response containing the created attribute. ```bash curl -X POST "http://api.example.com/entities/product/attributes" -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" -d '{ "data": { "type": "attributes", "attributes": { "code": "warranty_years", "frontend_label": "Warranty (Years)", "frontend_type": "number", "backend_type": "integer", "is_required": false, "is_filterable": true, "is_searchable": false, "default_value": "1" } } }' ``` -------------------------------- ### Insert New Entity Record Source: https://github.com/sunel/eav/blob/master/docs/master/model.md Demonstrates creating a new entity record using the `create` method, similar to standard Eloquent. Attributes are passed as an associative array. ```php use App\Products; Products::create([ 'name' => 'Flamethrower', 'sku' => '1HJK92', 'upc' => 'SHNDUU451888', 'description' => 'Not a Flamethrower', 'search' => 1 ]); ``` -------------------------------- ### Eloquent Model with Dynamic Attributes Source: https://context7.com/sunel/eav/llms.txt Demonstrates how to create, retrieve, and update entities with dynamic EAV attributes using Eloquent models. This allows developers to interact with EAV data as if they were standard Eloquent models, simplifying data manipulation. The attributes are assigned and accessed like regular model properties. ```php use App\Product; // Create product with dynamic attributes $product = new Product(); $product->sku = 'LAPTOP-XPS-15'; $product->name = 'Dell XPS 15 Laptop'; $product->description = 'High-performance laptop with 16GB RAM'; $product->price = 1299.99; $product->in_stock = true; $product->save(); // Retrieve product $product = Product::find(1); echo $product->name; // "Dell XPS 15 Laptop" echo $product->price; // 1299.99 // Update attributes $product->price = 1199.99; $product->save(); ``` -------------------------------- ### POST /entities/product/attributes/color/options Source: https://context7.com/sunel/eav/llms.txt Adds selectable options to a dropdown attribute for a specific entity. Use this endpoint to define new label/value pairs that will appear in the attribute's UI. ```APIDOC ## POST /entities/product/attributes/color/options\n\n### Description\nAdds selectable options to a dropdown attribute for a specific entity.\n\n### Method\nPOST\n\n### Endpoint\n/entities/product/attributes/color/options\n\n### Parameters\n#### Path Parameters\n- **entity** (string) - Required - Name of the entity (e.g., \"product\").\n- **attribute** (string) - Required - Attribute code (e.g., \"color\").\n\n#### Query Parameters\n_None_\n\n#### Request Body\n- **data** (array) - Required - List of option objects.\n - **label** (string) - Required - Display label for the option.\n - **value** (string) - Required - Stored value for the option.\n\n### Request Example\n```json\n{\n \"data\": [\n {\"label\": \"Silver\", \"value\": \"5\"},\n {\"label\": \"Gold\", \"value\": \"6\"},\n {\"label\": \"Rose Gold\", \"value\": \"7\"}\n ]\n}\n```\n\n### Response\n#### Success Response (200)\n- **data** (array) - Created attribute options.\n - **type** (string) - Resource type, always \"attribute-options\".\n - **id** (string) - Identifier of the option.\n - **attributes** (object) - Contains **label** and **value**.\n\n### Response Example\n```json\n{\n \"data\": [\n {\n \"type\": \"attribute-options\",\n \"id\": \"5\",\n \"attributes\": {\"label\": \"Silver\", \"value\": \"5\"}\n },\n {\n \"type\": \"attribute-options\",\n \"id\": \"6\",\n \"attributes\": {\"label\": \"Gold\", \"value\": \"6\"}\n },\n {\n \"type\": \"attribute-options\",\n \"id\": \"7\",\n \"attributes\": {\"label\": \"Rose Gold\", \"value\": \"7\"}\n }\n ]\n}\n``` ``` -------------------------------- ### Create Attribute with Select Options (PHP) Source: https://context7.com/sunel/eav/llms.txt This code snippet demonstrates how to create an attribute with select options using the EAV module. It defines an attribute with a backend type of integer and a frontend type of select. It adds multiple options with labels and integer values to the attribute. Dependencies: Eav\Attribute, Eav\AttributeOption, App\Product. Input: Entity type, attribute code, options. Output: Created attribute and updated product model. ```php use Eav\Attribute; use Eav\AttributeOption; use App\Product; // Create select attribute $attribute = Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'color', 'backend_type' => 'integer', 'frontend_type' => 'select', 'frontend_label' => 'Color', 'is_filterable' => true, ]); // Add options AttributeOption::add($attribute, [ ['label' => 'Red', 'value' => 1], ['label' => 'Blue', 'value' => 2], ['label' => 'Green', 'value' => 3], ['label' => 'Black', 'value' => 4], ]); // Use in model $product = Product::find(1); $product->color = 1; // Red $product->save(); // Query by option $redProducts = Product::whereAttribute('color', 1)->get(['*', 'name', 'color']); ``` -------------------------------- ### Create Custom Field Table Schema in PHP Source: https://github.com/sunel/eav/blob/master/docs/master/custom-table.md This snippet demonstrates how to create a custom table schema for a new field type using Laravel's Schema builder. It defines columns like value_id, entity_type_id, etc., and sets up foreign keys and indexes. Requires Laravel framework and assumes [ENTITY] and [FIELD_TYPE] placeholders are replaced with actual values. Note that this is for setting up the table structure in a migration file. ```php Schema::create('[field_type_table_name]', function (Blueprint $table) { $table->increments('value_id')->comment('Value ID'); $table->smallInteger('entity_type_id')->unsigned()->default(0)->comment('Entity Type ID'); $table->integer('attribute_id')->unsigned()->default(0)->comment('Attribute ID'); $table->integer('entity_id')->unsigned()->default(0)->comment('Entity ID'); $table->[FILED_TYPE]('value')->nullable()->comment('Value'); // update the type // Any additional fields // .... $table->foreign('entity_id') ->references('id')->on('[ENTITY]') // changes this (this is main entity table ) ->onDelete('cascade'); $table->unique(['entity_id','attribute_id']); $table->index('attribute_id'); $table->index('entity_id'); }); ``` -------------------------------- ### Retrieve EAV Attribute Options (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-options.md Retrieves an EAV attribute by its code and entity, loads its associated option values, and then accesses the options. This is useful for displaying selectable choices for an attribute. ```php $statusAttr = Eav\Attribute::findByCode('size', 'product'); $statusAttr->load('optionValues'); $statusAttr->frontend_type // This will return the type in this case 'select' $statusAttr->options(); ``` -------------------------------- ### Add Attribute Options via REST API Source: https://context7.com/sunel/eav/llms.txt Defines select options for dropdown attributes using a POST request to the API. It requires the 'Content-Type' and 'Accept' headers to be set to 'application/vnd.api+json'. The request body should be a JSON array of objects, each with 'label' and 'value'. The response is a JSON object confirming the added attribute options. ```bash curl -X POST "http://api.example.com/entities/product/attributes/color/options" \ -H "Content-Type: application/vnd.api+json" \ -H "Accept: application/vnd.api+json" \ -d '{ "data": [ {"label": "Silver", "value": "5"}, {"label": "Gold", "value": "6"}, {"label": "Rose Gold", "value": "7"} ] }' ``` ```json { "data": [ { "type": "attribute-options", "id": "5", "attributes": { "label": "Silver", "value": "5" } }, { "type": "attribute-options", "id": "6", "attributes": { "label": "Gold", "value": "6" } }, { "type": "attribute-options", "id": "7", "attributes": { "label": "Rose Gold", "value": "7" } } ] } ``` -------------------------------- ### Define Entity Attributes Source: https://context7.com/sunel/eav/llms.txt Defines attributes for a given entity using an Artisan command. This command allows for the creation of multiple attributes with specified backend and frontend types, labels, and other properties like required, filterable, and searchable. It generates migration code to add these attributes to the database. ```bash php artisan eav:make:attribute product --attributes sku:string,name:string,description:text,price:decimal,in_stock:boolean ``` ```php use Eav\Attribute; Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'sku', 'backend_type' => 'string', 'frontend_type' => 'text', 'frontend_label' => 'SKU', 'is_required' => true, 'is_filterable' => true, 'is_searchable' => true, ]); Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'name', 'backend_type' => 'string', 'frontend_type' => 'text', 'frontend_label' => 'Product Name', 'is_required' => true, 'is_searchable' => true, ]); Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'description', 'backend_type' => 'text', 'frontend_type' => 'textarea', 'frontend_label' => 'Description', 'is_searchable' => true, ]); Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'price', 'backend_type' => 'decimal', 'frontend_type' => 'number', 'frontend_label' => 'Price', 'is_filterable' => true, ]); Attribute::add([ 'entity_code' => 'product', 'attribute_code' => 'in_stock', 'backend_type' => 'boolean', 'frontend_type' => 'boolean', 'frontend_label' => 'In Stock', 'is_filterable' => true, 'default_value' => true, 'source_class' => \Eav\Attribute\Source\Boolean::class, ]); ``` -------------------------------- ### Add EAV Attribute with Options Array (PHP) Source: https://github.com/sunel/eav/blob/master/docs/master/ideology/attribute-options.md Adds a new EAV attribute named 'status' for the 'product' entity by directly providing an array of options. This is suitable for simple, static option sets defined within the code. ```php Eav\Attribute::add([ 'attribute_code' => 'status', 'entity_code' => 'product', 'backend_class' => null, 'backend_type' => 'int', 'backend_table' => null, 'frontend_class' => null, 'frontend_type' => 'select', // Assgin the type "select" 'frontend_label' => 'Status', 'source_class' => null, 'options' => [ '1' => 'Yes', '0' => 'No' ], 'default_value' => 0, 'is_required' => 0, 'required_validate_class' => null ]); ```