Terms table
- term_id
- name
- slug
Term_taxonomy table
- term_taxonomy_id
- term_id
- description
i want to show all record like "term_id , name , description
my Term model
public function TermTaxonomy(){
return $this->hasOne('TermTaxonomy');
}
my TermTaxonomy model
public function Term(){
return $this->belongsTo('Term');
}
my route
$term = new Term;
$categories = $term->all(['term_id', 'name']);
foreach($categories as $category){
echo $category->term_id . " " . $category->name . " " . "description of term_id should here" ;}
trying this code but Error Undefined property: Illuminate\Database\Eloquent\Collection::$TermTaxonomy
$e = new Term;
$f = $e->all(['term_id','name']);
echo $f->TermTaxonomy->description;
}
with the above code i want to return all description of each term_id, but i am confusing why i can show description if the object just 1 , like this code below
$a = new Term;
$b = $a->all(['term_id','name'])->find(8);
echo $b->TermTaxonomy->description . "<br>"; // work return description of $b;
so what is exactly one to one relationship function ? is one to one only work when the object just 1 ?
what about in my case ? is my logic wrong to show all description using relationship method ? then what must i do to show term id , name , description lists ?
thanks in advance, i am totally newbie in laravel.