<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Timeline extends Model
{
    use SoftDeletes;

    protected $dates = ['deleted_at'];

    protected $primaryKey = 'id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'titulo', 'language_id', 'image', 'ano',  'description'
    ];

    public function paginas()
    {
        return $this->belongsToMany('App\Pagina');
    }

    public function adicionarPagina($pagina)
    {

        if ($this->existePagina($pagina)) {
            return;
        }

        return $this->paginas()->attach($pagina); //attach - adiciona um relacionamento

    }

    public function existePagina($pagina)
    {
        return (bool) $this->paginas()->find($pagina->id);
    }

    public function removePagina($pagina)
    {
        return $this->paginas()->detach($pagina); //detach - remove um relacionamento
    }

    public function removeAllPagina()
    {
        return $this->paginas()->detach(); //detach - remove um relacionamento
    }

   
}
