im trying to sort the order of the rows. but when i try to find the value in the database it doesnot work. $products = Product::find($productsIds[$i]); doesnot find the value ..it would be of grat help if any one can find the error..thank you
<form method="post" action="{{ url('/ordering') }}" id="categoryOrderingForm">
<input type="hidden" value="{{ csrf_token() }}" name="_token" />
<input type="hidden" name="order" id="rowOrder" />
</form>
javascript is
<script>
$(function() {
$( "#sortable" ).sortable({
placeholder: "ui-state-highlight"
});
$( "#sortable" ).disableSelection();
$(".saveOrder").on("click", function() {
var selectedLanguage = new Array();
$('#sortable .sortable-row').each(function() {
selectedLanguage.push($(this).attr("id"));
});
$("#rowOrder").val(selectedLanguage);
$("#categoryOrderingForm").submit();
});
});
</script>
and the controller is
public function postOrdering()
{
$input = Request::all();
// dd($input);
if(isset($input["order"]) && count($input["order"]))
{
$productsIds = explode(",", $input["order"]);
// dd($productsIds);
if($productsIds && count($productsIds))
{
//dd(count($productsIds));
for($i=0; $i< count($productsIds); $i++)
{
//dd(count($productsIds[$i]));
//$products=Product::all();
// $products = Product::where("id", $productsIds[$i])->first();
$products = Product::find($productsIds[$i]);
//echo $products ;
//dd($products);
if( !is_null($products))
{
$products->products_order = $i;
$products->save();
}
}
}
}
return redirect()->back();
}