2
나는 다음과 같은 테이블, 데이터베이스 관계를 결정하는 것을 시도하고있다 : 각 게시물의 GANNA는 하나 개의 유형이 type_id
및 posts_type
(ID)가 동일 Laravel 쿼리 관계
posts
======
id
type_id
title
content
posts_type
==========
id
type_name
, 방법
을 Laravel에서 이것을 일대일 관계라고 정의합니까?모델 PostType
:
class PostType extends Eloquent {
protected $table = 'posts_type';
public function posts()
{
return $this->hasMany('Post', 'type_id', 'id');
}
}
// Get PostType (whereId=1) with all related posts
$postType = PostType::with('posts')->find(1);
모델 Post
:
감사
사람들은 두 개의 별도 modles를 잘입니까? – user3150060
예, 둘 다 다른 모델입니다. –
도움을 주셔서 대단히 감사합니다. – user3150060