I am creating a Ticket Reservation System and I want to insert data into the Database. As usual, I used HTML form and all the data goes to the database. I want to insert multiple seat numbers into the database. ( Seat numbers = items )

But , when I use this function in SeatsController.php , I am able to insert only one seat number. 

```
public function seatsinsert(Request $request) {

    $date = $request->input('date');
    $st = $request->input('st');
    $item = $request->input('items');

    $user = new Seats();
    $user->date = $date;
    $user->st = $st;
    $user->item = $item;

    $this->validate($request, [
        'date' => 'required'
    ]);

    $user->save();

    $request->session()->flash('Msg', 'Successfully Inserted !!');

    return redirect('Seats');
}

```

Then I changed my function in SeatsController.php like below to insert multiple seat numbers into the database. But , now I can't insert any of the data. In my console , it shows me this error - 

> 
> Failed to load resource: the server responded with a status of 500
>  (Internal Server Error).
> 
> 
> 

```
public function seatsinsert(Request $request)
    {

        $date = $request->input('date');
        $st = $request->input('st');
        $item = $request->input('items');
        //$item = item;

     $this->validate($request, [
            'date' => 'required'
        ]);   

    foreach($request->input("items") AS $item){
    $user = new Seats();
    $user->date = $date;
    $user->st = $st;
    $user->item = $item;

    $user->save();
}

            $request->session()->flash('Msg', 'Successfully Inserted !!');

            return redirect('Seats');

    }

```

How can I fix this ??

[Seat Structure Image](https://i.stack.imgur.com/E3nf8.png)

Here is my Seats.blade.php

```
<form class="form-horizontal" id="form1" method="POST" action="{{ route('seatsinsert') }}" enctype="multipart/form-data">    

    {{ csrf_field() }}    

    <div class="dt"> <br>

        @if(session()->has('Msg'))
        <h4 class="alert alert-success"> {{ session()->get('Msg') }} </h4>
        @endif    

        <div class="form-group row">
            <label for="example-date-input" class="col-2 col-form-label">Select Date :</label>
            <div class="col-10">
                <input class="form-control" type="date" name="date" placeholder="mm-dd-yyyy" id="example-date-input">
            </div>
        </div>

        <div class="form-group">
            <label for="exampleSelect1">Select Time :</label>
            <select name="st" class="form-control" id="exampleSelect1">
                <option>10.30 am</option>
                <option>1.30 pm</option>
                <option>4.30 pm</option>
                <option>7.30 pm</option>
            </select>
        </div>  

    </div>

    <h2 style="font-size:1.2em;font-family: Times New Roman;"> Choose seats by clicking below seats :</h2>

    <div id="holder"> 
        <ul id="place">
        </ul>    
    </div>

    <input type="submit" class="btn btn-primary" id="btnShowNew" value="Continue"> <br><br>

    <script type="text/javascript">

        $(function () {

            $('#btnShowNew').click(function (e) {
e.preventDefault();

var items = [];
$.each($('#place li.' + settings.selectingSeatCss + ' a'), function (index, value) {
    items.push($(this).attr('title'));
});

    console.log(items);

   // $(location).attr('href', 'Seats');

    $.ajax({
    type: "post",
    url: "{{ route('seatsinsert') }}",
    data: {
        _token: "{{ csrf_token() }}",
        items: items,
        date: $('input[name=date]').val(),
        st: $('select[name=st]').val()
    }, success: function(data){
        $("form").trigger("reset");  
        $('#success_message').fadeIn().html("Text");  
    }

    });
});
        });

    </script>
</form>

```

Here is my Route.

```
Route::post('seatsinsert', [
    'uses' => 'SeatsController@seatsinsert',
    'as' => 'seatsinsert'
]);

```

Here is Laravel Error Log

> 
> local.ERROR: Invalid argument supplied for foreach()
>  {"exception":"[object] (ErrorException(code: 0): Invalid argument
>  supplied for foreach() at
>  D:\wamp64\www\FinalProject\app\Http\Controllers\SeatsController.php:28)
> 
> 
> 

SeatsController.php:28 is

> 
> foreach($request->input("items") AS $item){
> 
> 
> 

I used dd($request->input('items')) ; and clicked submit button and nothing happens. But , when I check console from my browser it shows me this error - 

```
POST http://localhost/FinalProject/public/seatsinsert 500 (Internal Server Error)

ajax @ jquery.min.js:19
(anonymous) @ Seats:442
handle @ jquery.min.js:19
(anonymous) @ jquery.min.js:19
jquery.min.js:19 XHR finished loading: POST "

```