我想获得存在的所有color_code.code和manufacturer_bundle.name的唯一组合。他们通过一个表制造商连接筛选2列以获得独特组合的方法!与laravel /雄辩
这是我目前的代码。
$color_codes = ColorCode::select(['color_code.code', 'manufacturer_bundle.name'])->distinct()
->leftJoin('manufacturer_bundle', 'color_code.manufacturer_id' , '=' , 'manufacturer_bundle.id')
->get();
的问题它,是,只有选择那些收益领域,而不是实际的模型。所以,我希望能够做到这一点:
$color_code->manufacturer->name
这给了我
试图让非对象
财产的完整性:
的ColorCode:
Schema::create('color_code', function (Blueprint $table) {
$table->increments('id');
$table->string('code');
$table->index('code');
$table->integer('manufacturer_id');
$table->index('manufacturer_id');
$table->timestamps();
});
制造商
Schema::create('manufacturer', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->index('name');
$table->integer('manufacturer_bundle_id')->nullable();
$table->index( 'manufacturer_bundle_id');
$table->timestamps();
});
看到这里http://stackoverflow.com/questions/11277251/selecting-distinct-2-columns-combination-in-mysql从 – Toskan