copain
1 year ago
101
6
Laravel

How do i save multiple value of a fillable table into my database

Posted 1 year ago by copain

i have a fallible table and i want to save the value of the table into my database but i don't know to loop it any idea how?

Controller:

public function store(Request $request)
{
    $this->validate($request, [

        'student_name'=>'required|max:50|unique:leads,student_name',
        'gender'=>'required|max:50',
        'age'=>'required|max:2',



            ]);

            $leads=new Lead();
            $leads->student_name = $request->student_name;
            $leads->gender = $request->gender;
            $leads->age = $request->age;
            $leads->save();

            //Display a successful message upon save
              return redirect()->route('leads.create')
                  ->with('flash_message', 'Success.');
}

CREATE.BLADE

<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-bordered table-hover" id="tab_logic">
                <thead>
                    <tr >
                        <th class="text-center">
                            #
                        </th>
                        <th class="text-center">
                            StudentName
                        </th>
                        <th class="text-center">
                            Gender
                        </th>
                        <th class="text-center">
                            Age
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr id='addr0'>
                        <td>
                        1
                        </td>
                        <td>
                        <input type="text" name='student_name'  placeholder='StudentName' class="form-control"/>
                        </td>
                        <td>
                        <input type="text" name='gender' placeholder='Gender' class="form-control"/>
                        </td>
                        <td>
                        <input type="text" name='age' placeholder='AGE' class="form-control"/>
                        </td>
                    </tr>
                    <tr id='addr1'></tr>
                </tbody>
            </table>
        </div>
    </div>
    <a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a>
</div>

Please sign in or create an account to participate in this conversation.