How to change html Form to simple html:
{{ Form::select('sort', $sorts , $selectedSort ,array('onChange' => 'this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);')) }}
I change the form to this html form : what I have to add?
<select name="sort" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
@foreach($sorts as $sort)
<option value="">{{$sort}}</option>
@endforeach
</select>
controller:
$this->data['sorts'] = [
url('products') => 'Default',
url('products?sort=price-asc') => 'Price - Low to High',
url('products?sort=price-desc') => 'Price - High to Low',
url('products?sort=created_at-desc') => 'Newest to Oldest',
url('products?sort=created_at-asc') => 'Oldest to Newest',
];
$this->data['selectedSort'] = url('products');
private function _sortProducts($products, $request)
{
if ($sort = preg_replace('/\s+/', '', $request->query('sort'))) {
$availableSorts = ['price', 'created_at'];
$availableOrder = ['asc', 'desc'];
$sortAndOrder = explode('-', $sort);
$sortBy = strtolower($sortAndOrder[0]);
$orderBy = strtolower($sortAndOrder[1]);
if (in_array($sortBy, $availableSorts) && in_array($orderBy, $availableOrder)) {
$products = $products->orderBy($sortBy, $orderBy);
}
$this->data['selectedSort'] = url('products?sort='. $sort);
}
return $products;
}
and I tried to change this too:
<div class="form-group mx-sm-3 mb-2">
{{ Form::select('status', $statuses, !empty(request()->input('status')) ? request()->input('status') : null, ['placeholder' => 'All Status', 'class' => 'form-control input-block']) }}
</div>
to this:
<div class="form-group mx-sm-3 mb-2">
<select name="status" class="form-control input-block">
<option value="{{!empty(request()->input('status')) ? request()->input('status') : null}}" >All status</option>
@foreach($statuses as $status)
<option value="{{ $status }}" >{{ $status }}</option>
@endforeach
</select>
</div>
Controller:
$this->data['statuses'] = Order::STATUSES;
public function index(Request $request)
{
if ($request->input('status') && in_array($request->input('status'), array_keys(Order::STATUSES))) {
$orders = $orders->where('status', '=', $request->input('status'));
}
}
what I have to add or change to make select option work correctly and thank you very much