在Laravel中加入3个表

时间:2019-07-07 08:39:24

标签: php mysql laravel

我有三个表:

notes.id, businesses.id, businesses.title, businesses.description, businessimages.image

我想得到cordapp-example\workflows-java\build\nodes\PartyA>java -jar corda.jar

我该怎么办?

3 个答案:

答案 0 :(得分:1)

$data = DB::table('businesses')
            ->join('notes', 'notes.business_id', '=', 'businesses.id')
            ->join('businessimages', 'businessimages.business_id', '=', 'businesses.id')
            ->select('businesses.*', 'notes.note', 'businessimages.image')
            ->get();

答案 1 :(得分:0)

尝试这个兄弟希望它能起作用

$data = DB::table('notes)
            ->select(
                'notes.id',
                'businesses.id AS businesses_id',
                'businesses.title',
                'businesses.description',
                'businessesimages.image'
            )
            ->join('businesses', 'businesses.id', '=', 'notes.businesses_id')
            ->join('businessesimages', 'businessesimages.businesses_id', '=', 'notes.businesses_id')
            ->get();

探索更多:
Query Builder|Joining Table

答案 2 :(得分:0)

如何使用加入

$results = DB::table('businesses')
            ->select('notes.id as notes_id', 'businesses.id as business_id','businesses.title', 'businesses.description', 'businessimages.image' )
            ->join('notes', 'notes.business_id', '=', 'businesses.id')
            ->join('businessimages ', 'businessimages.business_id', '=', 'businesses.id')
            ->get();