【发布时间】:2015-01-12 18:55:52
【问题描述】:
我有一个users 表和follows 表和两个模型。我让用户离开连接以从表中获取数据,但我很困惑使用哪个模型和连接表(即)。
$user = Follows::select( 'users.id', 'users.username', 'users.photo' )
->leftJoin('users', 'follows.fk_users_id', '=', 'users.id')
->where('follows.follower_users_id' ,'=', $id)
->get();
或
$user = Users::select( 'users.id', 'users.username', 'users.photo' )
->leftJoin('follows', 'follows.fk_users_id', '=', 'users.id')
->where('follows.follower_users_id' ,'=', $id)
->get();
我在 Follows 模型中对此进行编码但我只需要来自users 表的数据,它满足follows 表的条件,需要你的帮助,因为我是 laravel 的新手。
我的问题是是使用Follows model and left join users table还是使用Users model and left join follow table
【问题讨论】:
-
But I only need data from users table where it meets the condition with follows table.... 在这种情况下,使用inner join?
标签: php mysql join laravel laravel-4