
我想在我的代碼中使用該錯誤,例如。
if(Not Found In Database) then
show alert"Data Not Found In Database"
如何使該錯誤包含在我的變數中?
*注意:我使用的是 Laravel-7
uj5u.com熱心網友回復:
首先檢查您是否有記錄:
$data = model::all();
if($data == NULL) {
echo "<script>alert('data not found')</script>"
}
uj5u.com熱心網友回復:
你可以試試
throw new \Exception("error");
編輯,通過使用添加檢查存在檔案的功能 curl
function checkUrlExistFile($url): bool {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($info == '200') return true;
return false;
}
和例子
if (!checkUrlExistFile($url)) {
throw new \Exception("error");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/336391.html
