How to check whether a model item is empty or not in laravel?
In this article, we will learn how can we check whether a model item is empty or not when searching a database for some data. I will give my project code you can ignore other codes and just use the item check code for your use.
code:
public function doAdd(Request $req){
$keyword = new Keyword();
$name = $req->keyword;
$keyword = Keyword::where('name', $name)->get();
if($keyword->isEmpty()){
dd("keyword empty");
}else{
dd("keyword already added");
}
}
No comments