0

I want to make a restaurant ordering system where the waiter can put more than 1 food menu,

I tried to make multiple inserts, but there was an error like this

Symfony\Component\Debug\Exception\FatalThrowableError syntax error, unexpected 'foreach' (T_FOREACH)

My Controller looks like this:

$orderdetail = new Order_detail;

    if(count($request->menu_id>0){
        foreach ($request->menu_id as $item) {
            $data_item = array( 'menu_id' => $request->menu_id[$item],
                                'order_id'=>$request->order_id[$item],
                                'qty'=>$request->qty[$item],
                                'subtotal'=>0 );
            Order_detail::insert($data_item);
        }
    });

My view

<form action="{{url('pelayan/order/detailorder')}}" method="POST" autocomplete="off" id="form-detail">
    @csrf
    <div class="panel-heading" id="judul-keterangan">

    </div>
    <hr>
    <div class="panel-body" id="detailorder">
        <div class="form-group">
            <label for="menu_id">Silahkan Pilih Menu</label>
            <select class="form-control text-uppercase menu_id" name="menu_id[]">
                <option>Silahkan Pilih pesanan</option>
                @foreach($menu as $m)
                <option value="{{$m->id}}">{{$m->name}}</option>
                @endforeach
            </select>
            <input type="text" name="qty[]" class="form-control qty" placeholder="Silahkan Masukkan Jumlah Menu">
        </div>
        <div id="tambahorder">

        </div>
        <button type="button" class="btn btn-success" id="tambah">Tambah Pesanan</button>
        <button type="button" class="btn btn-primary" id="simpanorder">Submit</button>
    </div>
</form>
2
  • Deleting the question after we solved your problem is very rude, Stack Overflow is not made to help you alone, it's for future readers who may find something useful in the question or answers Commented Oct 20, 2019 at 17:15
  • thank you for the solution, I am still unfamiliar with using stackoverflow, and there are some questions that I want to change because of that I intend to delete and create new questions, sorry Commented Oct 22, 2019 at 14:48

1 Answer 1

2

You made two mistakes

  1. You forgot to close the parentheses.
  2. you should check the count function after parentheses.

Now, your code looks like.

if(count($request->menu_id)>0){
            foreach ($request->menu_id as $item) { 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.