「hasOne」関係を持つリレーショナルテーブルを使用した雄弁なクエリでのソートの適用方法?この場合Eloquent Queryを使用したLaravelでの並べ替え
ブランドモデル
class Brand extends Eloquent
{
protected $table = 'brand';
protected $primaryKey = 'id';
protected $fillable = ['brand_name'];
public $sortable = ['brand_name'];
public function brandModel() {
return $this->hasOne('App\Brandmodel', 'brand_id')
->select('id', 'brand_id', 'brand_model_name');
}
}
---------------------------------------
class Brandmodel extends Eloquent
{
protected $table = 'brandmodel';
protected $primaryKey = 'id';
protected $fillable = ['brand_id'];
public $sortable = ['brand_model_name'];
}
我々は "BRAND_NAME" を使用して並べ替えることができます。しかし、私は "brand_model_name"を使って並べ替えることができません。
こんにちは、ありがとうございます。しかし、私はそれが可能ですか? "完全にEloquent" – Franklin
これはEloquentのクエリビルダを使用してテーブルに参加します。設定したリレーションシップメソッドを使用してこれを行うことはできません。これは「Eloqent-ly」と同じです。 – Dwight