Argument 1 passed, must be of the type array, string given

Argument 1 passed, must be of the type array, string given

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Argument 1 passed, must be of the type array, string given

You are encountering a specific exception thrown by Laravel's query builder: Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, string given. This error occurs because you are passing a raw string value directly into an whereIn clause that expects an array of values.

In your repository method, specifically within the logic handling file name searches, you have this condition:

if (request()->has('fileName') && request('fileName') != "") {
    $media = $media->whereIn('med_name', request('fileName'));
}

The issue lies in how the data is being retrieved from your form. Your HTML input field looks like this:

<input type="text" class="form-control" name="fileName" value="{{ request()->query('fileName') }}">

Because this is a single text input, request('fileName') returns a string (e.g., "report.pdf"). However, the whereIn method requires an array of values to construct a SQL IN (...) clause. When you pass a single string where an array is expected, Laravel's query builder attempts to bind this value as an array in its internal binding logic (cleanBindings), causing the type mismatch exception.

To fix this, you need to ensure that when a user searches by name, you are passing the correct data structure to whereIn. If the user intends to search for a specific file named "report.pdf", you should treat it as an array containing just that one item. You can achieve this by wrapping the request value in an array:

if (request()->has('fileName') && request('fileName') !== null) {
    $searchTerm = request('fileName');
    
    // Wrap the single string in an array to satisfy whereIn requirements
    $media = $media->whereIn('med_name', [$searchTerm]);
}

Alternatively, if your med_name column is unique and you simply want to filter for that specific filename regardless of how many results it theoretically returns (though usually, a file name implies uniqueness), you could use the standard where clause instead. This approach avoids the array requirement entirely:

if (request()->has('fileName') && request('fileName') !== null) {
    $media = $media->where('med_name', 'LIKE', '%' . request('fileName') . '%');
}

Using LIKE is often preferable for text searches because it allows partial matches. If a user types "report", you might want to see files named "quarterly_report.pdf" or just "report.png". The whereIn approach, even when wrapped in an array, performs an exact match only. It will not return files where the name contains the search term but is longer than the term itself unless the search term exactly matches the column value.

Regarding your form, you are correctly using name="fileName" without square brackets ([]). The brackets are reserved for multiple-value inputs like your file type dropdown (name="mediaType[]"). Since your file name input is a single string, the mismatch between the scalar input and the array expectation in the controller was the root cause.

There is also a potential performance consideration with your current implementation. In the select method of your repository, you are iterating through the paginated media results and then running a second query inside the loop:

foreach ($media as $key => $value) {
    // ...
    foreach (MediaLibrary::where('med_group', $value->med_group)->get() as $val) {
        // ...
    }
}

This creates a "N+1" query problem. If you have 15 files on the first page of your media library, Laravel will execute one initial query to get those 15 rows, and then 15 additional queries to fetch the paths for each group. For an application handling thousands of files, this will severely degrade performance as the dataset grows. It is highly recommended to refactor this logic using eager loading (e.g., $media->with('paths')->get()) or a single query with a join if your database schema supports it efficiently. While this isn't the direct cause of the exception you are seeing right now, addressing it will prevent future bottlenecks as your media library scales.

Our network