'users'와 'nests'테이블과 'nest_user'피벗 테이블 2 개가 있습니다. 내 피벗 테이블에서 필자는 이메일 주소를 필터링하여 관련 이메일 addreses가있는 모든 중첩을 가져올 수 있습니다.Laravel 4 피벗 테이블 (many to many) 로딩되지 않음
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username');
$table->text('bio');
$table->string('picture');
$table->string('email');
$table->string('password');
$table->integer('visits');
$table->integer('nest_id');
$table->timestamps();
});
}
public function up()
{
Schema::create('nests', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('info');
$table->integer('note_id');
$table->integer('website_id');
$table->integer('image_id');
$table->integer('video_id');
$table->integer('location_id');
$table->integer('user_id');
$table->integer('share_id');
$table->string('inviteAuth');
$table->string('tid');
$table->timestamps();
});
}
public function up()
{
Schema::create('nest_user', function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id');
$table->integer('nest_id');
$table->string('inviteEmail');
$table->timestamps();
});
}
는이 같은 사용자 ID에 따라이 문제를 할 수 없다 : 여기 내 scehma입니다
Route::get('/t1', function() {
$nest = User::find(2)->nest()->where('inviteEmail', '=', '[email protected]')->get();
foreach($nest as $nest)
echo $nest->name, ': ', $nest->pivot->inviteEmail, "</br>";
});
내가 둥지와 이름과 피벗에서 이메일 얻을 수 있습니다 - 최고를 .. 그러나, 나는 사용자 ID에 묶이지 않은 관련 이메일을 가진 모든 '둥지'를 찾고 싶다. 이 가까이 저를지고 있지만 여전히 작동하지 않습니다 :
Route::get('/t4', function() {
$users = User::all();
foreach($users as $users)
{
$nests = $users->with(array('nest' => function($query) {
$query->where('inviteEmail', '=', '[email protected]');
}))->get();
foreach($nests->nest as $nest)
{
echo $nest->name,"<br />";
}
}
});
나는이 오류가 무엇입니까 :
Undefined property: Illuminate\Database\Eloquent\Collection::$nest
합니다. 이것은 내가 Laravel과 가진 마지막 큰 논리/문법 장애물입니다. 전 문서를 기반으로 모든 구성을 시도했지만 아직 성공하지 못했습니다. 어떤 통찰력도 좋을 것입니다. 나는 너무 가까이에 있다고 느낍니다. – Danaia