laravel model relation for nested models

15
August 24, 2019, at 10:50 PM

I have three tables in a laravel project, namely: -center -payments -payment_details

center table:

payment table:

payment_details table:

now i want to select all data from payment_details table,i got it it displayed well, but there is a search option for payment_type for the list,But the search filed is not in payment-details table , so i don't know how to retrieve that fro m another table

Answer 1

If you are modeling your data with Eloquent relationships Do somthing like:

$type = 'c'; // For example
PaymentDetail::whereHas('payment', function ($query) use ($type) {
   $query->where('type', $type);
})->get();

If not you had to do join statement with payments table

READ ALSO
How can I skip a file when using os.listdir that has nothing written in it

How can I skip a file when using os.listdir that has nothing written in it

I am trying to go through all my files in a directory and make another text file that will eventually allow me to make plots out of my dataSome of the VariantLine# files do not contain any information in them because those variants were not found in any of my strains

47
What happened to pip in Windows, why is it no longer problematic to install packages? [on hold]

What happened to pip in Windows, why is it no longer problematic to install packages? [on hold]

Just now I saw myself in the situation where I had to install Paramiko on a new Windows machine

48
How to map elements to their index using streams?

How to map elements to their index using streams?

I get a stream of some custom objects and I would like to create a map Map<Integer, MyObject> with index of each object as keyTo give you a simple example:

46