我有两个表,一个叫做引号,另一个叫发票。我想检索所有没有发票的报价单。以下是我到目前为止的代码。我只能检索所有报价。我怎么能修改此查询查询从两个表使用laravel查询生成器+ mysql
$quotations = Quotation::lists('id', 'id');
mysql> describe quotations;
+--- ---- --------+------------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------------------+-----------------------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| customer_id | int(10) unsigned | NO | MUL | NULL | |
| employee_id | int(10) unsigned | NO | MUL | NULL | |
| exchange_rate | int(11) | NO | | 0 | |
| remark | varchar(255) | NO | | | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 | |
+---------------+------------------+------+-----+---------------------+-----------------------------+
mysql> describe invoices;
+--------------+------------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------------------+-----------------------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| quotation_id | int(10) unsigned | NO | MUL | NULL | |
| employee_id | int(10) unsigned | NO | MUL | NULL | |
| amount | int(11) | NO | | 0 | |
| balance | int(11) | NO | | 0 | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 | |
+--------------+------------------+------+-----+---------------------+-----------------------------+
感谢您的快速响应工作。请澄清你的答案。 '发票'不是一个属性。我想获取发票表 –
中没有条目的所有报价啊,我误读了关系。我会更新我的答案。 – jardis
感谢你的回答,你的回答是正确的,但你需要添加 - > get();为它工作。它应该像Quotation :: has('invoices','<', 1)-> get(); –