public function scopecountPets($query, $petsearch = '')
{
if (ChkAuth::userRole('admin') === 'admin') {
$sql = "SELECT COUNT(petid) as total FROM dc_pets WHERE petname LIKE :sch";
$params = [':sch' => $petsearch . "%"];
} else {
$userid = Auth::user()->id; //Ignore this is custom code
$sql = "SELECT COUNT(petid) as total FROM dc_pets WHERE petname LIKE :sch AND ownerid = :userid";
$params = [':sch' => $petsearch . "%", ':userid' => $userid];
}
$sth = DB::getPdo()->prepare($sql);
$sth->execute($params);
$kount = $sth->fetch(\PDO::FETCH_OBJ);
return $kount->total;
}
Just example....