Я пытаюсь сделать функцию поиска и возникли проблемы. У меня есть сообщение об ошибке преобразования массива в строку. Не могли бы вы научить меня правильному коду, пожалуйста?
Вот использование этой программы
1. Выберите значение пользователя, затем нажмите кнопку [search] (Это search.blade. php)
2. Результат поиска будет отображаться в файле result.blade. php
my Laravel Framework равен 6.18.8
search.blade. php
<form action="{{ route('search') }}" class="form-image-upload" method="POST" enctype="multipart/form-data">
{!! csrf_field() !!}
<div class="col-md-5">
<strong>TYPE</strong>
<select name="type" class="form-control">
<option value="-" selected>-</option>
<option value="j">j</option>
<option value="w">w</option>
</select>
</div>
<div class="col-md-5">
<strong>wc</strong>
<select name="wc" class="form-control">
<option value="N0" selected>0</option>
<option value="N1">1</option>
<option value="N2">2</option>
<option value="N3">3</option>
</select>
</div>
<div class="col-md-5">
<strong>FC</strong>
<select name="fc" class="form-control">
<option value="0" selected>0</option>
<option value="f01">f01</option>
<option value="f02">f02</option>
<option value="f03">f03</option>
</select>
</div>
<div class="col-md-5">
<strong>YC</strong>
<select name="yc" class="form-control">
<option value="0" selected>0</option>
<option value="yc1">yc1</option>
<option value="yc2">yc2</option>
</select>
</div>
<div class="col-md-5">
<strong>SC</strong>
<select name="sc" class="form-control">
<option value="Z01" selected>Z01</option>
<option value="Z02" selected>Z02</option>
<option value="Z03" selected>Z03</option>
</select>
</div>
<div class="col-md-2">
<br/>
<button type="submit" class="btn btn-success">Search</button>
</div>
</div>
</form>
result.blade. php
{!! csrf_field() !!}
<div class='list-group gallery'>
@if($images->count())
@foreach($images as $image)
<div class='col-sm-4 col-xs-6 col-md-3 col-lg-3'>
<a class="thumbnail fancybox" rel="ligthbox" href="/images/{{ $image->image }}">
<img class="img-responsive" alt="" src="/images/{{ $image->image }}" />
<div class='text-center'>
<small class='text-muted'></small>
</div> <!-- text-center / end -->
</a>
</div> <!-- col-6 / end -->
@endforeach
@endif
</div> <!-- list-group / end -->
ImageGalleryController. php
public function search()
{
$images = ImageGallery::get();
return view('search',compact('images'));
}
public function order(Request $request)
{
$data = $request->all();
$images = ImageGallery::where(['type',$request->$data['type']],
['wc',$request->$data['type']],
['fc',$request->$data['fc']],
['yc',$request->$data['yc']],
['sc',$request->$data['sc']])->get();
return view('result',compact('images'));
}
Веб. php
// search section
Route::post('search', 'ImageGalleryController@order');
Route::get ('search', 'ImageGalleryController@search');
ОБНОВЛЕНИЕ
Curent мой контроллер
public function search()
{
$images = ImageGallery::get();
return view('search',compact('images'));
}
public function order(Request $request) {
$data = $request->all();
$images = ImageGallery::where([
['type', $data['type']],
['wc',$data['type']],
['fc',$data['fc']],
['yc',$data['yc']],
['sc',$data['sc']]
])->get();
dd($images);
return view('search', compact('images'));
}