Product
Definition and Role:
The Product model represents a product within the application. It is used to manage and store information related to different products available in the system. This model is essential for handling product details, pricing, inventory, and categorization.
Relationships:
- Brand: The
Productmodel has a belongs-to relationship with theBrandmodel. This means that a product belongs to a specific brand./** @return BelongsTo<Brand> */
public function brand(): BelongsTo
{
return $this->belongsTo(Brand::class, 'shop_brand_id');
} - Categories: The
Productmodel has a many-to-many relationship with theCategorymodel. This means that a product can belong to multiple categories, and a category can have multiple products./** @return BelongsToMany<Category> */
public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'shop_category_product', 'shop_product_id', 'shop_category_id')->withTimestamps();
} - OrderItems: The
Productmodel has a one-to-many relationship with theOrderItemmodel. This means that a product can be associated with multiple order items./** @return HasMany<OrderItem> */
public function orderItems(): HasMany
{
return $this->hasMany(OrderItem::class, 'shop_product_id');
}
Traits:
HasFactory: Provides factory methods for creating model instances.InteractsWithMedia: Allows the model to interact with media files.LogsActivity: Enables activity logging for the model.
Attributes:
table: Specifies the database table name associated with the model.protected $table = 'shop_products';casts: Defines the data types of the model's attributes.protected $casts = [
'price' => 'decimal:2',
'is_visible' => 'boolean',
];
Activity Log Options:
- The
getActivitylogOptionsmethod returns the default logging options for the model.public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults();
}
Allowed Fields, Sorts, and Filters:
- The
Productmodel implements theHasAllowedFields,HasAllowedSorts, andHasAllowedFilterscontracts, which define the fields, sorts, and filters that can be used in queries.
public static function getAllowedFields(): array
{
return [
'id',
'name',
'slug',
'description',
'price',
'is_visible',
'created_at',
'updated_at',
];
}
public static function getAllowedSorts(): array
{
return [
'name',
'price',
'created_at',
'updated_at',
];
}
public static function getAllowedFilters(): array
{
return [
'name',
'price',
'is_visible',
];
}
for more info check the package Rupadana\ApiService docs
Table Columns
- shop_brand_id
- name
- sku
- barcode
- description
- qty
- security_stock
- featured
- is_visible
- suggested_price
- price
- cost
- type
- backorder
- requires_shipping
- return_by_days
- published_at
- seo_title
- seo_description
- weight_value
- weight_unit
- height_value
- height_unit
- width_value
- width_unit
- depth_value
- depth_unit
- volume_value
- volume_unit