簡體   English   中英

Laravel雄辯的模型

[英]Laravel eloquent model

我正在尋找一種查詢屬性的方法,同時刪除空間並使其小寫。

Artist Table
artist_id - '1'
artist_name - 'The Big Shot'

我希望能夠創建以下查詢

Artist::where('artist_name', '=', $request->input('artistname'));

Artist::where('thebigshot' = 'thebigshot')

對於Eloquent來說,刪除空格和小寫字符串不是一項任務-在將其傳遞給查詢之前,您應該做這件事,例如:

$name = strtolower(preg_replace('/\s+/', '', $request->input('artistname'));
Artist::where('artist_name', '=', $name)->get();

這是另一種方式,您將獲得相同的結果。 $ name = strtolower(str_replace('','','大人物')); // thebigshot Artist :: where('artist_name','=',$ name)-> get();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM