I want to get all unique combinations of color_code.code and manufacturer_bundle.name that exist. They are connected via a table manufacturer
this is my current code.
$color_codes = ColorCode::select(['color_code.code', 'manufacturer_bundle.name'])->distinct()
->leftJoin('manufacturer_bundle', 'color_code.manufacturer_id' , '=' , 'manufacturer_bundle.id')
->get();
The problem with it, is, that the select returns only those fields, and not actually the models. So I want to be able to do this:
$color_code->manufacturer->name
which gives me
Trying to get property of non-object
for completeness:
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();
});
Manufacturer
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();
});