小编Soh*_*415的帖子

Laravel Query Buider Group 通过未获取所有记录

我正在尝试从表中使用字段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 mysql group-by laravel laravel-5

2
推荐指数
1
解决办法
4577
查看次数

Laravel 方法同步不存在

岗位模型

<?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)

synchronization laravel

2
推荐指数
1
解决办法
3692
查看次数

标签 统计

laravel ×2

group-by ×1

laravel-5 ×1

mysql ×1

php ×1

synchronization ×1