F
F
fegedij3922020-09-26 00:24:30
Laravel
fegedij392, 2020-09-26 00:24:30

How to add data to the page in a dynamic list from another controller?

Help a newbie understand,
there is a page with a controller for adding a product,
Route::post('order-add', 'admin\[email protected]')->name('order-add');
Route::get('order-add', function () {
return view('cont.order-add');
})->name('order-add');

and a second page with a warehouse list controller,
Route::get('warehouses', 'admin\[email protected]');

product controller OrdersController
public function addorder(OrdersRequest $addord)
{
$addorder = new Orders();
$addorder->shop = $addord->input('shop');
$addorder->product = $addord->input('product');
$addorder->warehouses = $addord->input('warehouses'); //this line is now responsible for the name of the warehouse, I prescribe in the field manually
$addorder->save();

return redirect('/orders')->with('success', 'Order Added!');
}

warehouse controller WarehousesController
public function addwarehouses(WarehousesRequest $addwrk)
{
$addWarehouses = new Warehouses();
$addWarehouses->name = $addwrk->input('name'); //this is what I write manually when adding a product and should be a drop-down list
$addWarehouses->address = $addwrk->input('address');
$addWarehouses->phone = $addwrk->input('phone');
$addWarehouses->email = $addwrk->input(' email');
$addWarehouses->comment = $addwrk->input('comment');
$addWarehouses->save();

return redirect("Control-Panel")->with('success', 'Storage Added!');
}

How can I attach a drop-down list of warehouse names from the warehouse controller to the page for adding a product?

this is how I displayed products with a certain status on a separate page

public function ordernew()
    {
         $addorder = new Orders;
         return view('cont.order-new', ['allorder' => $addorder->where('status', '=', 'New')->get()]);
    }


and I can also sort by the warehouse selected manually if the drop-down list is done like this
<select name="">
<option>Выберите склад</option>
<option value="склад 1">склад 1</option>
<option value="склад 2">склад 2</option>
<option value="склад 3">склад 3</option>
</select>


but it is necessary that the name of the warehouse be dynamic because they often change and it is not convenient to write the name in the code every time.
and so I added a warehouse in the admin panel and add goods to it.

Thanks for the help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kokhan, 2020-09-26
@fegedij392

In the OrdersController controller, in the addorder method, you get a collection of warehouses:
$склады = ТаблицаСкладов::all();
Then you pass it to the product adding template: In the template, you make a drop-down list
return view('шаблон', compact('склады');

<select name="">
<option>Выберите склад</option>
@foreach($склады as $склад) 
<option value="{{ $склад->идентификатор }}">{{ $склад->название }}</option>
@endforeach
</select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question