I have the following select
<select class="form-control" id="from-location" name="from-location">
<option value="1">Inventory 1</option>
<option value="2">Inventory 2</option>
<option value="3">Inventory 3</option>
</select>
Each inventory has products (different, obviously, but same products can be in multiple inventories). I also have a select2 (searchable select) on the same page, and I want to render the products as options DEPENDING on what I choose in the first select. Example: if I select Inventory 2, then the select2 should render the products from Inventory 2, same for the others.
My Ajax request (not done yet because I am stuck):
$('#from-location').on('change', function() {
$.ajax({ //create an ajax request to display.php
type: "GET",
url: "/inventory_products",
dataType: "html", //expect html to be returned
success: function(response){
}
});
});
Route:
Route::get('/inventory-products', array('uses' => 'App\Http\Controllers\LogicForms@inventory_products'));
Controller:
class LogicForms extends Controller
{
public function inventory_products()
{
}
}
Tables structure:
inventories: id, name
products: id, name
invoice: id, date, number
invoice_products: id, invoice_id, product_id, quantity, code
product_stocks: id, product_id, inventory_id, invoice_product_id