Laravel: Escape “LIKE” clause?
问题 How can I escape a LIKE clause in Laravel/Eloquent? e.g., $search = Input::query('sSearch', ''); if($search !== '') { $paginatedBookings->where('first_name', 'LIKE', '%' . $search . '%'); } If $search contains a % or _ they need to be escaped. 回答1: The other answer forgets about escaping the escape character itself, here is a more robust solution: /** * Escape special characters for a LIKE query. * * @param string $value * @param string $char * * @return string */ function escape_like(string