2016-07-21 4 views
0

나는 테이블이 각각 PluginsUser 인 두 개의 을 가지고 있습니다. 나는 이라는 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 as pivot_user_id , plugins_user . plugins_id as pivot_plugins_id , plugins_user . contents as pivot_contents from plugins inner join plugins_user on plugins . id = plugins_user . plugins_id where plugins_user . user_id = 1 limit 1)

이 버그 수정에 도와주세요. 당신의 테이블 이름

`plugin_user` 

하지만 쿼리가

`plugins_user` 

당신은 테이블 이름으로 Plugin 모델을 갱신 할 필요가있을 수 있습니다 검색 마이그레이션처럼

감사

+0

이미 마이그레이션을 실행하기를 원하십니까? 그리고'Plugins' 모델의 코드는 무엇입니까? –

+1

Easy as that : plugin_user! == plugins_user 오류로 인해 정확하게 문제가 알려줍니다. plugins_user하지만 plugin_user를 정의하지 않았습니다. 관계에서 참조 된 테이블 이름을 변경할 수 있습니다. https://laravel.com/docs/5.1/eloquent-relationships#many-to-many –

+0

@ArifulHaque 이미 그렇게했습니다. –

답변

1

이 보이는 .

1

문제는 테이블 이름입니다. 오류는 plugins_user을 찾고 있지만 마이 그 레이션에서는 plugin_user 테이블에 s가 없습니다.라는 오류가 표시됩니다. 이 플러그인

수 어느 테이블 이름을 변경하거나 관계의 참조 테이블을 변경하는 방법을 확인 https://laravel.com/docs/5.1/eloquent-relationships#many-to-many에 가야 모델 의 이름 플러그인로 인해 수 있습니다.

관련 문제