i want to make a filter by shops.
Controller:
function filter(Request $request){
$goods = Good::select('shop_id')->where('shop_id', '=', $request->id)->get();
$shops = Shop::all ();
return view('filter')->with(['goods' => $goods, 'shops' => $shops]);
}
Migrations:
Schema::create('goods', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('amount');
$table->integer('shop_id');
$table->timestamp('onPurchase');
$table->timestamps();
});
Schema::create('shops', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('adress')->nullable();
$table->timestamps();
});
Form to get id:
<form action = "" method="post">
<select name="id">
@foreach ($shops as $shop)
<option value=""> </option>
@endforeach;
</select>
<br><br>
<input type="submit" class="btn btn-primary" value="Pasirinkti">
</form>
It wont print the list based on selected ID that i get via $_POST. Any help appreciated.
via Benua