How to Check If a String Contains Another String in Laravel 9
In this lesson, we are going to see how to check If a string contains another string in Laravel 9, the contains helper method is used to check if a string contains another string.
The Str::contains helper method
The contains() method checks if the provided string contains another string if yes it returns true otherwise it returns false.
use Illuminate\Support\Str;
Str::contains('Darija coding', 'coding');
// true
The Str::contains helper method is case sensitive
You can disable the case-sensitive search by using the code below:
use Illuminate\Support\Str;
Str::contains('Darija coding', 'CODING', true);
// true