我在用户表中有用户的图片,我希望根据我发送的邀请访问这些图片。试图抓取与我发送的所有邀请相关的所有用户图片。我有一个这样的模型结构:
class User extends Eloquent
{
public static $table = 'users';
public static $accessible = array('username', 'email', 'picture', 'password');
public function nests()
{
return $this->has_many('Nest');
}
class Nest extends Eloquent
{
public static $table = 'nests';
public function user()
{
return $this->belongs_to('User');
}
class Invite extends Eloquent
{
public static $table = 'invite';
public function nest()
{
return $this->belongs_to('Nest');
}
这是我的迁移:
{
Schema::create('users', function($table) {
// auto incremental id (PK)
$table->increments('id');
// varchar 32
$table->string('username', 32);
$table->string('email', 64);
$table->string('picture');
$table->string('password');
$table->string('role');
// boolean
$table->boolean('true');
// created_at | updated_at DATETIME
$table->timestamps();
});
}
{
Schema::create('nests', function($table) {
// auto incremental id (PK)
$table->increments('id');
// varchar 32
$table->string('nestname', 128);
$table->text('info');
$table->integer('user_id');
// boolean
$table->boolean('active');
// created_at | updated_at DATETIME
$table->timestamps();
});
}
{
Schema::create('invite', function($table) {
$table->increments('id');
$table->text('mypeeps');
$table->integer('user_id');
$table->integer('nest_id');
$table->string('email', 128);
$table->timestamps();
});
}
这是我试图获取照片但它不起作用的方式:
$users = DB::table('users')
->join('nests', 'nests.user_id', '=', 'users.id')
->join('invite', 'invite.nest_id', '=', 'nests.id')
->where_nest_id($id)
->get(array('users.picture', 'users.username'));