samedi 26 janvier 2019

Laravel Eloquent With Filter

I am trying to get all user with their roles and transactions.But transaction have a specific condition.I don't want to give condition in model cause model method used many where.

But I am getting error

Unknown column 'transaction.short_code' Or If I remove transaction.short_code then Unknown column 'short_code'

My code

   $transactions = User::select('id','first_name','last_name')
       ->with(['roles','transaction'=> function($query){
           $query->where('transaction.short_code','point_transfer')->get();
    }])->get();

User Model

public function transaction(){
    return $this->hasMany(Transaction::class);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire