laravel查詢數據返回的結果
在插入數據庫的時候,發現查詢數據返回的結果是一個對象;即使是空數據 返回的不是true或者false
那么要判斷該結果是否查詢有結果 該如果呢?
學習源頭:
https://douyasi.com/laravel/eloquent_collection_detect_empty.html
https://stackoverflow.com/questions/20563166/eloquent-collection-counting-and-detect-empty
不能用is_set() empty() 來判斷 因為不管成功與否 都是true
$result = Model::where(...)->get(); //不為空則 if ($result->first()) { } if (!$result->isEmpty()) { } if ($result->count()) { }