首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用laravel对crossJoin结果进行排序

问如何用laravel对crossJoin结果进行排序
EN

Stack Overflow用户
提问于 2019-09-27 11:00:47
回答 3查看 3.1K关注 0票数 0

我使用交叉连接得到两个表的结果。但是当我试图在视图中显示它时,我会得到这个错误。

调用数组上的成员函数crossJoin()

那么,如何将其安排在HTML表中呢?看上去像下面。

代码语言:javascript
复制
barcode | desc | qty | branch1 | branch2 | branch3 | branch4
------------------------------------------------------------
123456  | lenovo| 100  |  null   |  null   |  null   |  null   
252666  | hp    | 100  |  null   |  null   |  null   |  null  
895566  | acer  | 70   |  null   |  null   |  null   |  null  
968411  | apple | 800  |  null   |  null   |  null   |  null  

这是我的密码

代码语言:javascript
复制
$receiving = DB::select('select * from branch')
               ->crossJoin('allocation_stocks')->get();
return view('operation.home', ['data' => $receiving]);

表allocation_stocks

代码语言:javascript
复制
barcode | desc | qty 
----------------------
123456  | lenovo| 100  
252666  | hp    | 100 
895566  | acer  | 70   
968411  | apple | 800  

表支

代码语言:javascript
复制
brach_name|
-----------
branch1 
branch2 
branch3 
branch4 
EN

回答 3

Stack Overflow用户

发布于 2019-09-27 11:08:13

尝试这个查询。它应该能工作

代码语言:javascript
复制
$receiving = DB::table('branch')
               ->crossJoin('allocation_stocks')
               ->get();
return view('operation.home', ['data' => $receiving]);
票数 2
EN

Stack Overflow用户

发布于 2019-09-27 11:13:15

要执行“交叉连接”,请使用crossJoin方法,其中包含要交叉连接的表的名称。

交叉连接在第一个表和连接表之间生成一个笛卡儿积:

代码语言:javascript
复制
$receiving = DB::table('branch')
    ->crossJoin('allocation_stocks')
    ->get();

另请参阅:

接合

票数 0
EN

Stack Overflow用户

发布于 2019-09-27 11:56:26

代码语言:javascript
复制
You can see the query builder in laravel here.

交叉连接

代码语言:javascript
复制
$result = DB::table('branch')
               ->crossJoin('allocation_stocks')
               ->get();

return view('operation.home', ['data' => $result]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58133224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档