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/SBogers110/franciscaansebeweging.nl/app/Komma/Pages/Models/Page.php
<?php

namespace Komma\Pages\Models;

/**
 * Short description for the file.
 *
 * @author      Komma <support@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */
class Page extends \Komma\Kms\Pages\Models\Page
{
    public $kmsClass = 'Komma\\Kms\\Pages\\Models\\Page';

    /**
     * Get blocks with are linked by the kms blocks in pages
     *
     * @return mixed
     */
    public function blocks(){
        return $this->belongsToMany('Komma\Blocks\Models\Block', 'page_blocks')->with(['translation', 'images']);
    }

    public function block(){
        return $this->hasOne('Komma\Blocks\Models\Block', 'code_name', 'code_name')->with(['translation', 'images']);
    }

    public function travels()
    {
        return $this->hasMany('Komma\Travels\Models\Travel', 'travel_type')
            ->with(['translation', 'translation.route', 'images'])
            ->where('active', 1)
            ->orderBy('ownTravel', 'DESC')
            ->orderBy('start_date', 'ASC');
    }


    /**
     * Get the translation for the current language
     *
     * @return Collection
     */
    public function translation()
    {
        /**
         * On the translation model is an BelongsTo relation.
         * We want to collect the current translation.
         * Therefore we create a hasOne relation
         * Where we will select the page_translation,
         * Join on the languages table
         * And set the current Locale as the languages.iso_2
         *
         */
        return $this->hasOne('Komma\Pages\Models\PageTranslation')
            //We only need the translation
            ->select('page_translations.*')
            //Join the languages
            ->join('languages', 'languages.id', '=', 'page_translations.language_id')
            //Get only the language with the correct lang
            ->where('languages.iso_2', '=', \App::getLocale());
    }

    /**
     * Get all translations
     *
     * @return Collection
     */
    public function allTranslations(){
        return $this->hasMany('Komma\Pages\Models\PageTranslation')
            //Join the languages
            ->join('languages', 'languages.id', '=', 'page_translations.language_id')
            ->whereIn('languages.iso_2', \Config::get('app.availableLanguages'))
            //We only need the translation and language iso
            ->select('page_translations.*', 'languages.iso_2')
            ->orderBy('languages.id');
    }
}