I'm trying to make search function and having problem. I have Array to string conversion error message. Could you teach me right code please?
Here is this program usage
1.User select value then click [search] button (This is search.blade.php)
2.Search result will display at result.blade.php
my Laravel Framework is 6.18.8
search.blade.php
<form action="" class="form-image-upload" method="POST" enctype="multipart/form-data">
<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
<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/">
<img class="img-responsive" alt="" src="/images/" />
<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'));
}
Web.php
// search section
Route::post('search', 'ImageGalleryController@order');
Route::get ('search', 'ImageGalleryController@search');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire