HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/Lacom/lacom.nl/app/KommaApp/Shop/Products/ProductComposite/ProductComposite.php
<?php

namespace App\KommaApp\Shop\Products\ProductComposite;

use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\HasImagesInterface;
use App\KommaApp\Shop\Categories\Kms\CategorizableInterface;
use App\KommaApp\Shop\Categories\Models\Category;
use App\KommaApp\Shop\Products\ProductGroup\ProductGroup;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

/**
 * Represents a basic product that a user can put in a cart
 *
 * Class Product
 * @package App
 */
class ProductComposite extends AbstractTranslatableModel implements CategorizableInterface, HasImagesInterface
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['title'];

    public $thumbnail = false;

    public function groups()
    {
        return $this->belongsToMany(ProductGroup::class);
    }

    public function images():HasMany
    {
        /**
         *
         * On the Image model is an MorphTo relation
         * By using a hasMany relation:
         * where the imageable_type is filled in with the KmsClass
         * And the imageable_id is set as the foreign_id,
         * we can collect the images of the given model directly.
         *
         */
        return $this->hasMany(Image::class, 'imageable_id')
            ->where('imageable_type', '=', ProductComposite::class);
    }

    /**
     * We belong to many categories
     *
     * @return MorphToMany
     */
    public function categories(): MorphToMany
    {
        return $this->morphToMany(Category::class, 'product_categorizable');
    }

    public function translations(): HasMany
    {
        return $this->hasMany(ProductCompositeTranslation::class);
    }
}