Terms table:
- term_id
- name
- slug
Term_taxonomy table:
- term_taxonomy_id
- term_id
- description
My Term model:
public function TermTaxonomy(){
return $this->hasOne('TermTaxonomy');
}
public function saveCategory($data){
$validator = Validator::make($data,$this->rules);
if($validator->passes()){
$this->name = $data['name'];
$this->slug = $data['slug'];
$this->save();
$TermTaxonomy = new TermTaxonomy;
$TermTaxonomy->taxonomy = 'category';
$TermTaxonomy->description = $data['TermTaxonomy']['description'];
if($this->TermTaxonomy()->save($TermTaxonomy)){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
$this->errors = $validator;
return false;
}
}
My TermTaxonomy model:
public function Term(){
return $this->belongsTo('Term');
}
I have read Laravel 4 docs inserting related models
Sometimes you may wish to save not only a model, but also all of its relationships. To do so, you may use the push method:
Saving A Model And Relationships
$user->push();
Then I read @Antonio Carlos Answer in this question he says it can replace 2 save()
syntax with push()
, I think this good way because less code.
in my saveCategory()
method it work like expected , but I want to know how I can use push()
in my saveCategory()
method? Already google that but nothing.
I am new in Laravel and any help will be appreciated.