<?php

namespace App\Modules\Utilitarios\Models;

use Illuminate\Database\Eloquent\Model;
use App\Modules\Utilitarios\Models\Art_familia;
use DB;
class Art_familia extends Model
{
   public $timestamps = false;

   protected $guarded = [];

   protected $fillable = [];

   protected $table_pivot = 'familia_relation';

   public function relation_has($id){
		$data = DB::table($this->table_pivot)->where('articulos_id', $id)->get();
      $relation = array();
		foreach ($data as $a) {
			$familia = Art_familia::find($a->art_familias_id);
			if (!empty($familia)) {
				$relation[] = (Object)array('id_familia'=>$familia->id,'nombre_familia'=>$familia->nombre,'slug'=>$familia->slug,'id_relation'=>$a->id);
			}
		}
		return $relation;
   		
   }
   public function add_relation(){
   		DB::table($this->table_pivot)->insert(
    		['articulos_id' => $this->articulos_id, 'art_familias_id' => $this->art_familias_id]
		);
   }
}
