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/SBogers10/rentman2019.komma.pro/app/Komma/Solutions/Models/Solution.php
<?php
/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\Solutions\Models;

use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Languages\Models\Language;
use App\Komma\Sites\HasSiteInterface;
use App\Komma\Sites\Models\Site;
use App\Komma\SolutionGroups\Models\SolutionGroup;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class Page
 *
 * @property int site_id
 * @property int lft
 * @property int rgt
 * @property int tree
 * @property-read Collection|\App\Komma\Languages\Models\Language[] $languages
 * @property-read Collection|\App\Komma\Sites\Models\Site[] $sites
 * @property-read \App\Komma\Solutions\Models\SolutionTranslation $translation
 * @property-read Collection|\App\Komma\Solutions\Models\SolutionTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $active
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution whereUpdatedAt($value)
 * @property-read Collection|\App\Komma\Documents\Models\Document[] $documents
 * @property-read Collection|\App\Komma\Documents\Models\Document[] $images
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Solutions\Models\Solution query()
 */
class Solution extends AbstractTranslatableTreeModel implements HasSiteInterface, DisplayNameInterface, DocumentableInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;

    protected $table = 'solutions';

    protected $class = self::class;

    protected $guarded = ['id'];

    /**
     * Gets the translation models for this model
     *
     * @return HasMany that resolves to AbstractTranslationModel instances
     */
    public function translations(): HasMany
    {
        return $this->hasMany(SolutionTranslation::class);
    }

    public function languages(): BelongsToMany
    {
        return $this->belongsToMany(Language::class, 'solution_translations')
            ->withPivot('slug', 'name', 'description')
            ->withTimestamps();
    }

    public function solutionGroup(): BelongsTo
    {
        return $this->belongsTo(SolutionGroup::class);
    }

    /**
     * Get the site or sites for this model
     *
     * @return BelongsToMany
     */
    public function site(): BelongsTo
    {
        return $this->belongsTo(Site::class);
    }

    /**
     * Some logic that makes it possible to overrule images by translation images
     *
     * @return Collection|null
     */
    public function languageImages(): ?Collection
    {
        // Load and check that there are images
        $this->load('images');
        if (! isset($this->images) || $this->images->isEmpty()) {
            return null;
        }

        // First grab the global defined images
        $globalImages = $this->images->where('key', '=', 'Documents-solutions');

        // Then grab the translation images
        $translationImages = $this->images->where('key', '=', 'Documents-hero_images-'.\App::getLocale());

        // If there are translation images we return those
        if (isset($translationImages) && $translationImages->isNotEmpty()) {
            return $translationImages->values();
        }

        // Else we return the global images
        return $globalImages->values();
    }
}