我正在尝试从表中使用字段groupBy获取数据。我正在使用这个查询typetransaction
DB::table($this->table)
->select()
->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
->groupBy('type')
->get();
Run Code Online (Sandbox Code Playgroud)
但它并没有给出complete records. 我的表中有10多条记录。但它只给了我两个。一个用于 type=1,另一个用于 type=2。它仅从每种类型中选择记录。我期待我能得到所有transactions基于condition分组的内容two result set。有人知道为什么会这样吗?
岗位模型
<?php
namespace App\Model\User;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function tags(){
return $this->belongsToMany('App\Model\User\Tag','post__tags', 'post_id', 'tag_id');
}
public function categories() {
return $this->belongsToMany('App\Model\User\Category','category__posts','post_id', 'category_id');
}
}
Run Code Online (Sandbox Code Playgroud)
类别模型
<?php
namespace App\Model\User;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
public function posts(){
return $this->belongsToMany('App\Model\User\Category','category__posts', 'post_id', 'category_id');
}
}
Run Code Online (Sandbox Code Playgroud)
标签模型
<?php
namespace App\Model\User;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
public function posts() {
return $this->belongsToMany('App\Model\User\Post','post__tags','post_id','tag_id');
}
}
Run Code Online (Sandbox Code Playgroud)
后控制器.php
public funcion store()
{
// do validation here
try{
$post = new …Run Code Online (Sandbox Code Playgroud)