'laravel select2 on submit receive blank page
have an issue. When submitting a form with select2 receive a completely blank page. don't understand why controller doesn't work. just need send store id.
<form id='filter' action="{{ route("admin.product.filter") }}" enctype="multipart/form-data">
@csrf
@method('get')
<select name="store" id="store" class="form-control store">
<option value="0">All</option>
@foreach($stores as $store)
<option value="{{$store->id}}">{{$store->name}}</option>
@endforeach
</select>
<div>
<input class="btn btn-danger" type="submit">
</div>
</form>
via select2
$('.store').select2({
templateResult: formatState
});
function formatState (state) {
if (!state.id) {
return state.text;
}
var baseUrl = "http://localhost/gadmin/public/shops ";
var $state = $(
'<span><img src="' + baseUrl + '/' + state.element.value + '.png" class="img-flag" /> ' + state.text + '</span>'
);
return $state;
};
$('#filter').on('select2:select', function (e) {
$('#filter').submit();
});
My controller
public function filter(Request $request)
{
$item=Product::with('translation:name,product_id')->get();
$stores=Store::select('id','name')->get();
return view('admin.product.index', compact('item','stores'));
}
and my route
Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('product/filter','Admin\ProductController@filter')->name('product.filter');
});
Solution 1:[1]
I know I'm late for this, especially that I still don't have a concrete solution but at least I could manage to find the problem causing this behavior.
If you remove the enctype="multipart/form-data" part from your HTML template, the blank page error will be resolved.
Of course, now I need to find a way to use the multipart form ecoding type without somehow breaking PHP...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darkavid |
