【发布时间】:2019-08-29 09:07:13
【问题描述】:
我创建了一对多的关系。这是模型类。
class Photo extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
}
class User extends Authenticatable
{
public function photos(){
return $this->hasMany('App\Photo');
}
}
然后我尝试检索照片:
$photos = User::find(1)->photos->where('photo', 'ut.jpg')->first();
这是我得到的查询日志。我没有看到照片='ut.jpg'。那么 laravel 是如何生成 SQL 的呢?
select * from `photos` where `photos`.`user_id` = 1 and `photos`.`user_id` is not null
【问题讨论】:
标签: php laravel laravel-5.8