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/SBogers85/equichecker.com/app/KommaApp/Core/Services/coreService.php
<?php

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace KommaApp\Core\Services;

class CoreService
{

    public $language;

    /**
     * This method will check of the Subelement exist.
     * And if the count is greater than zero.
     * If so returns the subElement
     *
     * @param $element
     * @param $subElement
     * @return bool
     */
    public function getSubElement($element, $subElement, $whereField = null, $whereVal = null)
    {
        if (!$element->has($subElement)) return false;
        if ($element->$subElement->count() == 0) return false;

        if ($whereField && $whereVal) return $element->$subElement->where($whereField, $whereVal);

        return $element->$subElement;
    }

    /**
     * This method will set the from the model.
     * First it will check if the element has languages.
     * Then it wil check if the element has an translation,
     * in the active locale, an set this Languae
     *
     * @param $element
     * @return bool| abbort | Language
     */
    public function setLanguageByModel($element){
        if(!$element->languages)return false;

        //Check if the element has an translation for the given language
        if(!$language= $element->languages->where('iso_2',\App::getLocale())->first()){
            return \App::abort(400, 'Translation not found!');
        }
        $this->language  = $language;
        return $language;
    }

    public function getTranslation($element){
        if(!$this->setLanguageByModel($element)) return false;

        $translation = $element->translations->where('language_id', $this->language->id)->first();

        return $translation;

    }

}