如何找到 laravel 5.3 中哪个查询失败?
how to find which query failed in laravel 5.3?
我正在尝试构建一个基于订阅的应用程序,所以我有一个 table,其中包含作为字符串的名称,作为日期的 valid_till。
我正在尝试通过以下方式获取 table:
$today = Carbon::today();
$active = Domain::where([
['name', $name],
['valid_till', '>=', $today],
])->first();
if(isset($active))
{
return "Name fetched";
}
else
{
return "Name not there";
}
它工作正常。我想检查 "name found but validity expired" 这样的错误。请指导我。
谢谢。
first()
将 return null
如果查询没有找到,所以使用 is_null
检查是否有对象。
if (!is_null($active)) {
// Object exists.
} else {
// No result.
}
当您使用 get()
时,您应该使用 result->isEmpty()
或 empty($result)
或 count($result)
或 $result->count()
来检查集合是否为空。
我正在尝试构建一个基于订阅的应用程序,所以我有一个 table,其中包含作为字符串的名称,作为日期的 valid_till。
我正在尝试通过以下方式获取 table:
$today = Carbon::today();
$active = Domain::where([
['name', $name],
['valid_till', '>=', $today],
])->first();
if(isset($active))
{
return "Name fetched";
}
else
{
return "Name not there";
}
它工作正常。我想检查 "name found but validity expired" 这样的错误。请指导我。
谢谢。
first()
将 return null
如果查询没有找到,所以使用 is_null
检查是否有对象。
if (!is_null($active)) {
// Object exists.
} else {
// No result.
}
当您使用 get()
时,您应该使用 result->isEmpty()
或 empty($result)
或 count($result)
或 $result->count()
来检查集合是否为空。