[英]Laravel Query how to check if column starts with 0
我有一個帶有Registration
和Category
表的 CRUD 應用程序。 在RegistrationController
,我使用了一個帶有 Category 的查詢,所以我做了另一個查詢。 我掙扎檢查是否每一個其他gender_id
具有cte_from
其開始於0。 cte_gender_id
具有1,2,或3。1 =人,2 =婦女3 =未確定和Nd cte_from
是年齡范圍。
因此在數據庫中: cte_gender_id
為 1, cte_from
為 0,然后另一行cte_gender_id
為 1, cte_from
為 25,然后另一個cte_gender_id
為 1 和 35,依此類推,但gender_id
2 和 3。
注冊控制器
$gender_ids = ['1', '2', '3'];
foreach ($gender_ids as $gender_id) {
$category = Categorie::where('cte_distance_id', $distance_id)
->where('cte_gender_id', $gender_id)
->where('cte_from',)
->first();
if (is_null($category)) {
return back()->with("errorMessage", "Category not found");
}
}
所以我想要,例如,如果gender_id 是1 並且cte_from 不是從0 開始,它已經沒有通過。
您可以使用WHERE cte_from LIKE '0%'
來測試字符串是否以0
開頭。
在此查詢中, %
用於通配符。
或者在 Laravel 查詢構建器中:
->where('cte_from', 'LIKE', '0%')
// Or if it doesn't start with a 0
->where('cte_from', 'NOT LIKE', '0%')
嘗試..
->where('cte_from', 'LIKE', '0%')
$gender_ids = ['1', '2', '3'];
foreach($gender_ids as $gender_id){
$category = Categorie::where('cte_distance_id', $distance_id)
->where('cte_gender_id', $gender_id)
->where('cte_from', 'LIKE', '0%')
->first();
if(is_null($category)){
return back()->with("errorMessage", "Category not found");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.