i am working on a project about a restaurant.In the wine section i have listed all the wines and i have done a dropdown list that shows all the categories of wines from my database and that is ok, i need to do another value on dropdown that shows me again all the wines after i have selected 1 category. Thanks in advance.
This is my Controller
public function index()
{
$wines = Wines::where('visible','yes')->where('delete','no')->get();
$wines_categories = Wines_Categories::where('visible','yes')->where('delete','no')->get();
return view('wines.wines', ['wines' => $wines,'wines_categories' => $wines_categories]);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index_filtered(Request $request)
{
if(isset($request->category))
{
$wines = Wines::where('visible','yes')->where('delete','no')->where('id_wine_category',$request->category)->get();
}
else
{
$wines = Wines::where('visible','yes')->where('delete','no')->get();
}
$wines_categories = Wines_Categories::where('visible','yes')->where('delete','no')->get();
return view('wines.wines', ['wines' => $wines,'wines_categories' => $wines_categories]);
}
This is my dropdown section
{!! Form::open(array('route' => 'wines_filtered','role' => 'form', 'enctype' => 'multipart/form-data')) !!}
<div class="col-md-4 col-sm-2 pull-right"style="margin-top: 50px">
<div class="select-style input-round med-input shop-shorting-full">
<select name="category" onchange="this.form.submit()"style="font-weight: bold; color: #ac2d24;text-align: center">
<option value="" > Scegli Categoria </option>
@foreach($wines_categories as $wines_category)
<option value=""></option>
@endforeach
</select>
</div>
</div>
{!! Form::close() !!}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire