0
更新之前。在組(0.00秒)Lavarel 5,更新1行,但會影響多行。我不知道爲什麼,請建議
更新記錄
mysql> select parcel_id,type, status ,accepted_at,accepted_user,submitted_at,submitted_user, updated_at from parcel_deliveries;
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| parcel_id | type | status | accepted_at | accepted_user | submitted_at | submitted_user | updated_at |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| RI013502995TH | 1 | 1 | 2015-09-29 15:01:44 | hnong | 2015-09-29 17:19:56 | hnong | 2015-09-30 16:50:11 |
| EN064142823TH | 1 | 1 | 2015-10-02 16:17:39 | hnong | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:12:39 |
| EN064142823TH | 2 | 1 | 2015-10-02 16:39:43 | hnong1 | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:12:39 |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
3行,我打算只更新1行(parcel_id = EN064142823TH,類型= 2)
$a = App\Parcel_delivery::where('parcel_id', 'EN064142823TH')
->where('type', '=', 2)
->where('postal_code', '10170')
->orderBy('created_at', 'desc')->first();
=> App\Parcel_delivery {#829
parcel_id: "EN064142823TH",
type: 2,
status: 1,
accepted_at: "2015-10-02 16:39:43",
accepted_user: "hnong1",
submitted_at: "2015-10-02 16:48:24",
submitted_user: "hnong",
destination_id: null,
person_type: null,
signature: null,
comment: "",
run_no: null,
}
>>> $a->status = 5;
=> 5
>>> $a->save(); => true
後更新。在集(0.00秒)
mysql> select parcel_id,type, status ,accepted_at,accepted_user,submitted_at,submitted_user, updated_at from parcel_deliveries;
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| parcel_id | type | status | accepted_at | accepted_user | submitted_at | submitted_user | updated_at |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| RI013502995TH | 1 | 1 | 2015-09-29 15:01:44 | hnong | 2015-09-29 17:19:56 | hnong | 2015-09-30 16:50:11 |
| EN064142823TH | 1 | 5 | 2015-10-02 16:17:39 | hnong | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:14:43 |
| EN064142823TH | 2 | 5 | 2015-10-02 16:39:43 | hnong1 | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:14:43 |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
3行,我不知道爲什麼另一個紀錄是更新還(parcel_id = EN064142823TH,類型= 1)。
請建議。非常感謝你。
謝謝。我添加了自動增量ID作爲主鍵,它的工作原理。 –
@onthemoon如果它解決了您的問題,請標記答案爲已接受的答案。 – ShaunUK