Eloquent 如何实现 LEFT OUTER JOIN 查询

请问一下如何用 Eloquent 实现 LEFT OUTER JOIN 查询:#

Sql 语句

SELECT A.id,A.name,B.name fatherName,A.add,A.code,A.`level` FROM FatherArticle A LEFT OUTER JOIN FatherArticle B ON A.fatherid=B.id

表结构迁移:

Schema::create('FatherArticle',function (Blueprint $table){
            $table->uuid('id')->primary()->comment('文章分类ID');
            $table->string('code','120')->comment('文章分类标示');
            $table->string('name','225')->comment('文章分类名称');
            $table->integer('level')->default('0')->comment('排序');
            $table->integer('add')->comment('添加时间');
            $table->string('fatherid')->comment('上级ID');\
            $table->string('describe','')->nullable()->comment('分类描述');
        });

请问大家如何实现的,刚用这套框架不久,之前看了 “模型关联” 不太明白原理,

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

$this->hasMany($this, 'fatherid', 'id')

5年前 评论
jansiel (楼主) 5年前

多看看别人的源码

5年前 评论