save value of an array

Posted 8 months ago by copain

how do i save the value of array into my controller?

result of array using DD


array:4 [▼
  "_token" => "kjYvkKfuOkiBacn1EC0EzfeK5AitRYbXADE2E5RI"
  "student_name" => array:3 [▼
    0 => "ROBERT"
    1 => "cindy"
    2 => "rico"
  "age" => array:3 [▼
    0 => "12"
    1 => "13"
    2 => "14"
  "gender" => array:3 [▼
    0 => "MALE"
    1 => "female"
    2 => "MALE"


public function store(Request $request)
        $this->validate($request, [
                        $leads=new Lead();
                        $leads->student_name = $request->student_name;
                       $leads->gender = $request->gender;
                       $leads->age = $request->age;

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


 <form action="{{route('')}}" method="POST">
    <div class="col-sm-12">
    <div class="container">
    <div class="row">
        <div class="col-md-12">
            <div data-role="dynamic-fields">
                <div class="form-inline">
                    <div class="form-group">
                        <label class="sr-only" for="field-name">Field Name</label>
                        <input type="text" class="form-control" id="field-name"  name="student_name[]" placeholder="Field Name">
                    <div class="form-group">
                        <label class="sr-only" for="field-value">Field Value</label>
                        <input type="text" class="form-control" id="field-value"  name="age[]" placeholder="Field Value">
                    <div class="form-group">
                        <label class="sr-only" for="field-agent">Field Agent</label>
                        <input type="text" class="form-control" id="field-agent"  name="gender[]" placeholder="Field Agent">
                    <button class="btn btn-danger" data-role="remove">
                        <span class="glyphicon glyphicon-remove"></span>
                    <button class="btn btn-primary" data-role="add">
                        <span class="glyphicon glyphicon-plus"></span>
                </div>  <!-- /div.form-inline -->
            </div>  <!-- /div[data-role="dynamic-fields"] -->
        </div>  <!-- /div.col-md-12 -->
    </div>  <!-- /div.row -->
<button type="submit" class="btn btn-success">SUBMIT</button>
<a href="{{route('leads.index')}}" class="btn btn-success">CANCEL</a>

<!--end of container-->

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.