以下のようなモデルクラスがあるとして、
<?php class Test extends Base { protected $appends = [ 'is_fuga', ]; protected $fillable = [ 'id', 'name', ]; ~~~~~~ この辺いろんなカラムの定義 ~~~~~~ public function test(): BelongsTo { return $this->belongsTo(test::class); } /** * fugaを返却する * @return bool */ public function getIIsFugaAttribute() { // ここ実際はもっと違う条件 return $this->test->where('type', 1)->count() > 0; } }
この場合、
Testモデルのfugaが1のものを取得しようとしてクエリを組むと、
model->where('is_fuga', true);
以下のような列未定義エラーが出ます。
(PDOException(code: 42703): SQLSTATE[42703]: Undefined column: 7 ERROR:
独自で追加したフィールドをモデルのwhere句に入れ込むことは不可能なのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/17 09:11
2022/06/17 09:50