<?php

namespace App\Modules\Utilitarios\Models;

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

   protected $guarded = [];

   protected $fillable = [];

   protected $table_pivot = 'tag_relation';

 	public function relation_has($id){
		$data = DB::table($this->table_pivot)->where('articulos_id', $id)->get();
		$relation = array();
		foreach ($data as $a) {
			$tag = Tag_art::find($a->tag_arts_id);
			if (!empty($tag)) {
				$relation[] = (Object)array('id_tag'=>$tag->id,'nombre_tag'=>$tag->nombre,'slug'=>$tag->slug,'id_relation'=>$a->id);
			}
		}
		return $relation;
   		
   }
   public function add_relation(){
   		DB::table($this->table_pivot)->insert(
    		['tag_arts_id' => $this->tag_id,'articulos_id' => $this->articulos_id]
		);
   }

}
