How to check if a specific value exists in a collection in illuminate/collections?

To check if a specific value exists in a collection using Illuminate/Collections, you can make use of the contains() method. Here's an example:

use Illuminate\Support\Collection; $collection = collect([1, 2, 3, 4, 5]); if ($collection->contains(3)) { echo "Value exists in the collection."; } else { echo "Value does not exist in the collection."; }

In this example, we create a collection of numbers and then use the contains() method to check if the value 3 exists in the collection. If the value exists, it will echo "Value exists in the collection." Otherwise, it will echo "Value does not exist in the collection."