【发布时间】:2015-12-02 08:54:03
【问题描述】:
表格:
categories
--id
materials
--id
category_material
--id
--category_id
--material_id
型号:
class Material extends Model {
public function categories(){
return $this->belongsToMany('App\Category');
}
}
class Category extends Model {
public function materials(){
return $this->belongsToMany('App\Material');
}
}
我需要“category_id = 1”中的所有材料
尝试:
$category_id = '1';
$materials = Material::with('categories')->where('category_id', $category_id)->get();
未知列“materials.category_id”
$category_id = '1';
$materials = Material::with(['categories',function($query) use ($category_id){
$query->where('category_id', $category_id);
}])->get();
Builder.php 第 792 行中的错误异常: explode() 期望参数 2 是字符串,给定对象
请帮帮我。
【问题讨论】:
标签: php laravel-5 eloquent many-to-many