誰か助けてください。私はlaravelを初めて使ったので、selectタグからmysqlに配列を格納する必要があり、私はこのerorrを持っています。 SQLSTATE [42S02]:ベーステーブルまたはビューが見つかりません::(account_code_project
project_pj_id
= 1からaccount_code_ac_id
を選択SQL)を1146表 'cmsystem.account_code_project' が存在しません。これは、belongsToMany()関数を使用することと関係があるようです。私のコードはここで何をすればいいのですか?SQLSTATE [42S02]:ベーステーブルまたはビューが見つかりません(belongsToMany)Laravel 5.4
はここproject_table
//project table
Schema::create('projects', function(Blueprint $table)
{
$table->increments('pj_id');
$table->string('pj_title',100);
$table->string('pj_description');
});
がここにここにaccountcodesテーブル
//codes
Schema::create('accountcodes', function(Blueprint $table)
{
$table->increments('ac_id');
$table->string('ac_code',100)->nullable();
$table->string('ac_description')->nullable();
});
だ二つのテーブルのための中間テーブルだのです
//intermediate table
Schema::create('code_project', function(Blueprint $table){
$table->increments('id');
$table->integer('project_id')->unsigned();
$table->foreign('project_id')->references('pj_id')->on('projects');
$table->integer('account_id')->unsigned();
$table->foreign('account_id')->references('ac_id')->on('accountcodes');
});
プロジェクトコントローラー
//ProjectController
public function store(Request $request)
{
$this->validate($request,[
'pj_title'=>'required',
'pj_description'=>'required',
]);
$project = new project;
$project->pj_title = $request->pj_title;
$project->pj_description = $request->pj_description;
$project->save();
$project->accounts()->sync($request->accounts, false);
return redirect('/projectlist');
}
の
モデル
//AccountCode
protected $table = 'accountcodes';
public function projects()
{
return $this->belongsToMany('App\Project');
}
//Project
protected $table = 'projects';
public function accounts()
{
return $this->belongsToMany('App\AccountCode');
}
ありがとうございました。
のように見えます私は私のモデルの両方でそれを指定する必要がある必要がありますので、両方のモデルの代表の両方を宣言することによってそれを解決しましたか?私はこのような意味です 返す$ this-> belongsToMany( 'App \ Project'、 'code_project'); return $ this-> belongsToMany( 'App \ AccountCode'、 'code_project'); – kalawadei
@ClaudeDizonはい、ピボットテーブルを使用する必要がある場合はどこでも可能です。問題は、命名規則に従わないことです。 – apokryfos
belongsToManyタグに "code_project"を追加しても何も変更されないので、テーブル名を "accountcode_project"に変更しました。それでもまだエラーは同じです。私はこれについてどんな誤りも見ない。私は何をすべきでしょうか?ごめんなさい、ありがとう。 – kalawadei