<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Page extends Model
{

    protected $fillable = [
        'title',
        'text_short',
        'text',
        'slug',
        'image',
        'online',
        'web',
        'email',
        'facebook',
        'twitter',
        'instagram',
        'youtube'
    ];

    public function advs()
    {
        return $this->hasMany('App\PageAdv');
    }

    public function getAdvs()
    {
        
        $advs['Sopra 234x60 1'] = array();
        $advs['Sopra 234x60 2'] = array();
        $advs['Sopra 234x60 3'] = array();
        $advs['Sopra 234x60 4'] = array();
        $advs['Sotto 234x60 1'] = array();
        $advs['Sotto 234x60 2'] = array();
        $advs['Sotto 234x60 3'] = array();
        $advs['Sotto 234x60 4'] = array();
        $advs['728x90'] = array();

        $pages_advs = $this->advs()->where('online', '=', true)->orderBy('sort')->get();
        foreach($pages_advs as $a)
        {
            $advs[$a->position][] = $a;
        }
        return $advs;

    }

}
