Mysql - SQLSTATE[42S22]: Column not found: 1054 Unknown column
<p>This is my the code of my query :</p>

<pre><code>$payments = DB::table('payments')
                    -&gt;join('invoices', 'invoices.id', '=', 'payments_invoices.invoice_id')
                    -&gt;join('payments_invoices', 'payments.id', '=', 'payments.payment_id')
                    -&gt;leftJoin('clients', 'clients.id', '=', 'payments.client_id')
                    -&gt;leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
                    -&gt;where('payments.account_id', '=', Auth::user()-&gt;account_id)
                    -&gt;where('payments.is_deleted', '=', false)
                    -&gt;where('invoices.is_deleted', '=', false)
                    -&gt;where('clients.is_deleted', '=', false)
                    -&gt;where('contacts.deleted_at', '=', null);
</code></pre>

<p>when I try to show the result of this query it gives me :</p>

<pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'payments_invoices.invoice_id' in 'on clause' (SQL: select `payments`.`payment_date`, `payments`.`amount`, `invoices`.`public_id`, `invoices`.`invoice_number`, `clients`.`name` as `client_name`, `contacts`.`email`, `contacts`.`first_name`, `contacts`.`last_name`, `clients`.`currency_id`, `clients`.`public_id` as `client_public_id`, `clients`.`user_id` as `client_user_id` from `payments` inner join `invoices` on `invoices`.`id` = `payments_invoices`.`invoice_id` inner join `payments_invoices` on `payments`.`id` = `payments`.`payment_id` left join `clients` on `clients`.`id` = `payments`.`client_id` left join `contacts` on `contacts`.`client_id` = `clients`.`id` where `payments`.`account_id` = 1 and `payments`.`is_deleted` = 0 and `invoices`.`is_deleted` = 0 and `clients`.`is_deleted` = 0 and `contacts`.`deleted_at` is null and `contacts`.`is_primary` = 1 order by `payments`.`payment_date` desc limit 50) 
</code></pre>

<p>knowing that this query works correctly :</p>

<pre><code>$query = DB::table('payments')
                    -&gt;join('accounts', 'accounts.id', '=', 'payments.account_id')
                    -&gt;join('clients', 'clients.id', '=', 'payments.client_id')
                    -&gt;join('invoices', 'invoices.id', '=', 'payments_invoices.invoice_id')
                    -&gt;join('payments_invoices', 'payments.id', '=', 'payments.payment_id')                     
                    })
                    -&gt;leftJoin('payment_types', 'payment_types.id', '=', 'payments.payment_type_id')
                    -&gt;where('clients.is_deleted', '=', false)
                    -&gt;where('payments.is_deleted', '=', false)
                    -&gt;where('invitations.deleted_at', '=', null)
                    -&gt;where('invoices.deleted_at', '=', null)
                    -&gt;where('invitations.contact_id', '=', $contactId)
                    );
</code></pre>

<p>what should I do please ??</p>