Answers for "laravel where condition on relationship"

PHP
1

laravel where condition on relationship

App\Request::where('id',4)
    ->whereHas('quotes', function ($query) {
        $query->where('status','=','3');
    })
    ->with('quotes','sourceTable','destinationTable')
    ->get();
Posted by: Guest on November-30-2020
0

laravel adding condition to relation

class Game extends Eloquent {
    // many more stuff here

    // relation without any constraints ...works fine 
    public function videos() {
        return $this->hasMany('Video');
    }

    // results in a "problem", se examples below
    public function available_videos() {
        return $this->videos()->where('available','=', 1)->get();
    }
}
Posted by: Guest on March-30-2020

Code answers related to "laravel where condition on relationship"

Browse Popular Code Answers by Language