나는 테이블이 각각 Plugins
및 User
인 두 개의 을 가지고 있습니다. 나는 이라는 migration
에 이라는 이름의 이라는 many to many relationship
을 가지고 있습니다. 나는 관계 기능 다음 한 User model
에서Laravel many to many relationship error
public function up()
{
Schema::create('plugin_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('plugins_id');
$table->json('contents');
$table->timestamps();
});
}
: 다음
는스키마입니다
public function userplugins(){
return $this->belongsToMany('App\Plugins')->withPivot('contents');
}
다음 코드 행을 가져 오는 동안 :
$user = User::findorFail($id);
return $user->userplugins()->first()->contents;
I 다음 오류가 발생했습니다 :
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nitsbuilder.plugins_user' doesn't exist (SQL: select
plugins
.*,plugins_user
.user_id
aspivot_user_id
,plugins_user
.plugins_id
aspivot_plugins_id
,plugins_user
.contents
aspivot_contents
fromplugins
inner joinplugins_user
onplugins
.id
=plugins_user
.plugins_id
whereplugins_user
.user_id
= 1 limit 1)
이 버그 수정에 도와주세요. 당신의 테이블 이름
`plugin_user`
하지만 쿼리가
`plugins_user`
당신은 테이블 이름으로 Plugin
모델을 갱신 할 필요가있을 수 있습니다 검색 마이그레이션처럼
감사
이미 마이그레이션을 실행하기를 원하십니까? 그리고'Plugins' 모델의 코드는 무엇입니까? –
Easy as that : plugin_user! == plugins_user 오류로 인해 정확하게 문제가 알려줍니다. plugins_user하지만 plugin_user를 정의하지 않았습니다. 관계에서 참조 된 테이블 이름을 변경할 수 있습니다. https://laravel.com/docs/5.1/eloquent-relationships#many-to-many –
@ArifulHaque 이미 그렇게했습니다. –