存在するcolor_code.codeとmanufacturer_bundle.nameの一意の組み合わせをすべて取得したいと思います。それらはテーブルメーカーを通じて接続されていますユニークな組み合わせの2つの列をフィルタリングする方法! laravel/eloquentと
これは私の現在のコードです。
$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
完全を期すために非オブジェクト
のプロパティを取得しようとすると
私に与える:だから私はこれを行うことができるようにしたいです
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