传递的参数 1,必须是数组类型,给定的字符串
Argument 1 passed, must be of the type array, string given
我正在与 Laravel 5.8 合作,我创建了一个页面来查看存储在 media_library
table.
中的所有上传文件
我得到的所有数据都是这样的:
public function __construct(MediaLibraryRepository $mediaLibraryRepoObject)
{
$this->mediaLibraryRepoObject = $mediaLibraryRepoObject;
}
public function index()
{
$res = $this->mediaLibraryRepoObject->select();
$media = $res["media"];
$files = $res["files"];
$extensions = [
'jpg', 'png', 'bmp', 'gif', 'jfif', 'mp4', 'mkv', 'flv', 'mov', 'avi', 'wmv', 'mp3', 'pdf', 'doc', 'docx', 'pptx', 'xls', 'xlsx', 'zip', 'rar'
];
return view('admin.mediaLibrary.index', compact('media','files', 'extensions'));
}
如您所见,我在这里调用了一个存储库,在 index()
方法中,我调用了该存储库的 select()
方法,它位于此处:
public function select()
{
$media = MediaLibrary::where('med_dimension', 'full');
if (request()->has('mediaType') && request('mediaType') != "")
$media = $media->whereIn('med_extension', request('mediaType'));
if (request()->has('fileName') && request('fileName') != "")
$media = $media->whereIn('med_name', request('fileName'));
$media = $media->latest()->paginate(15);
$files = [];
foreach ($media as $key=>$value) {
$files[$key]['med_name'] = $value->med_name;
$files[$key]['med_group'] = $value->med_group;
$files[$key]['med_size'] = $value->med_size;
$files[$key]['med_extension'] = $value->med_extension;
foreach (MediaLibrary::where('med_group', $value->med_group)->get() as $val) {
$files[$key]['path'][$val->med_dimension] = $val->med_path;
}
}
return ["files"=>(object) $files,"media"=>$media];
}
因此我需要在 Blade 中添加一个搜索表单来搜索文件名,因此我尝试了以下代码:
if (request()->has('fileName') && request('fileName') != "")
$media = $media->whereIn('med_name', request('fileName'));
但是它给我这个错误:
传递给 Illuminate\Database\Query\Builder::cleanBindings() 的参数 1 必须是数组类型,字符串给定,在
中调用
所以这里出了什么问题?我该如何解决这个问题?
这是我的表格:
<div class="row">
<div class="col-md-4" style="padding-right: 0px !important;">
<label for="mediaType">File type:</label>
<select type="text" class="form-control select2" name="mediaType[]" multiple>
<option value="">Select</option>
@foreach($extensions as $ext)
<option value="{{ $ext }}"
@if(request()->has('mediaType') && request('mediaType') != "")
@foreach(request()->query('mediaType') as $f)
@if($ext == $f)
selected
@endif
@endforeach
@endif
>
{{ $ext }}
</option>
@endforeach
</select>
</div>
<div class="col-md-4" style="padding-right: 0px !important;">
<label for="mediaType">File name:</label>
<input type="text" class="form-control" name="fileName" value="{{ request()->query('fileName') }}">
</div>
<div class="col-md-4" style="padding-top: 25px; padding-left: 0px !important;">
<button class="btn btn-primary float-left">Search</button>
</div>
</div>
</div>
whereIn
方法验证给定列的值是否包含在给定数组中。
更改代码:
$media = $media->whereIn('med_name', request('fileName'));
$media = $media->where('med_name', request('fileName'));
我正在与 Laravel 5.8 合作,我创建了一个页面来查看存储在 media_library
table.
我得到的所有数据都是这样的:
public function __construct(MediaLibraryRepository $mediaLibraryRepoObject)
{
$this->mediaLibraryRepoObject = $mediaLibraryRepoObject;
}
public function index()
{
$res = $this->mediaLibraryRepoObject->select();
$media = $res["media"];
$files = $res["files"];
$extensions = [
'jpg', 'png', 'bmp', 'gif', 'jfif', 'mp4', 'mkv', 'flv', 'mov', 'avi', 'wmv', 'mp3', 'pdf', 'doc', 'docx', 'pptx', 'xls', 'xlsx', 'zip', 'rar'
];
return view('admin.mediaLibrary.index', compact('media','files', 'extensions'));
}
如您所见,我在这里调用了一个存储库,在 index()
方法中,我调用了该存储库的 select()
方法,它位于此处:
public function select()
{
$media = MediaLibrary::where('med_dimension', 'full');
if (request()->has('mediaType') && request('mediaType') != "")
$media = $media->whereIn('med_extension', request('mediaType'));
if (request()->has('fileName') && request('fileName') != "")
$media = $media->whereIn('med_name', request('fileName'));
$media = $media->latest()->paginate(15);
$files = [];
foreach ($media as $key=>$value) {
$files[$key]['med_name'] = $value->med_name;
$files[$key]['med_group'] = $value->med_group;
$files[$key]['med_size'] = $value->med_size;
$files[$key]['med_extension'] = $value->med_extension;
foreach (MediaLibrary::where('med_group', $value->med_group)->get() as $val) {
$files[$key]['path'][$val->med_dimension] = $val->med_path;
}
}
return ["files"=>(object) $files,"media"=>$media];
}
因此我需要在 Blade 中添加一个搜索表单来搜索文件名,因此我尝试了以下代码:
if (request()->has('fileName') && request('fileName') != "")
$media = $media->whereIn('med_name', request('fileName'));
但是它给我这个错误:
传递给 Illuminate\Database\Query\Builder::cleanBindings() 的参数 1 必须是数组类型,字符串给定,在
中调用所以这里出了什么问题?我该如何解决这个问题?
这是我的表格:
<div class="row">
<div class="col-md-4" style="padding-right: 0px !important;">
<label for="mediaType">File type:</label>
<select type="text" class="form-control select2" name="mediaType[]" multiple>
<option value="">Select</option>
@foreach($extensions as $ext)
<option value="{{ $ext }}"
@if(request()->has('mediaType') && request('mediaType') != "")
@foreach(request()->query('mediaType') as $f)
@if($ext == $f)
selected
@endif
@endforeach
@endif
>
{{ $ext }}
</option>
@endforeach
</select>
</div>
<div class="col-md-4" style="padding-right: 0px !important;">
<label for="mediaType">File name:</label>
<input type="text" class="form-control" name="fileName" value="{{ request()->query('fileName') }}">
</div>
<div class="col-md-4" style="padding-top: 25px; padding-left: 0px !important;">
<button class="btn btn-primary float-left">Search</button>
</div>
</div>
</div>
whereIn
方法验证给定列的值是否包含在给定数组中。
更改代码:
$media = $media->whereIn('med_name', request('fileName'));
$media = $media->where('med_name', request('fileName'));