php - Searching in Laravel relationship for second table -


i have 2 table having polymorphic relationships.

table1 history

id|amount|type|created_at|updated_at 

table2 accounts

id|amount|name|account_number|accountable_id|accountable_type|created_at|updated_at 

history have summary of accounts table. accounts table having polymorphic fields (accountable)

now executing query in history table results includes accounts table also.

the question want search data in accounts table payer name in account table. when hit query on history table pass payer name can fetch accounts having specific payer name.

you may need set relationship between history , accounts can query along lines of:

$histories = histories::wherehas(         'accounts'         function ($query) use ($name) {             $query->where('name', $name);         }     )->get(); 

but question not clear, , don't have names field in accounts in limited schema provided, can't give better answer.

read more here:

https://laravel.com/docs/5.1/eloquent-relationships


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -