<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Prodotto extends Model
{
    protected $table = 'prodotti';
    
    /**
     * Prende gli interventi associati al prodotto
     */
    public function interventi()
    {
        return $this->belongsToMany('App\Intervento', 'intervento_prodotto', 'intervento_id', 'prodotto_id');
    }  

    /**
     * Prende la categoria associata al prodotto
     */    
    public function categoria() {
        //return $this->belongsTo('App\Anagrafica', 'id', 'cliente_id' );
        return $this->hasOne('App\Categoria', 'id', 'categoria_id' );
    }    
    
    public function scopeOrder($query)
    {
        return $query->orderBy('descrizione', 'asc')->orderBy('prezzo', 'asc');
    }      
}
