Hi,
First you have to specify your foreign key at the table 'cms_text' that references 'post_id' on 'cms_post'.
Then you should specify local keys and foreign keys in your Model's relations (because it does not match with the naming conventions of laravel)
// Post Model
public function teksten()
{
return $this->hasOne('Text', 'text_post_id', 'post_id');
}
// Text Model
public function berichten()
{
return $this->belongsTo('Post', 'text_post_id', 'post_id');
}
Finally, to invoke the relation, you should use the same name as specified in your model.
// your view
{{ $p->teksten->text_content }}
Hi Othmanus,
Great, your solution solved my problem!
In order for laravel to recognize it automaticly i should remove the text_ from text_post_id so both tables have the same key in their table if i understand i right?
A big thankyou!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community