mardi 16 mars 2021

My laravel form is not submitting. What can I do? Please help me and Thank you in advance

Name of my controller is CustomerController. This is my controller. There are 5 fillable field out of which 1 is image.

public function store(Request $request)
{
    $request->validate([
        'name' => 'required',
        'category' => 'required',
        'mobile_number_1' => 'required|min:10|max:10',
        'mobile_number_2' => 'min:10|max:10',
        'aadhar_card' => 'required',
    ]);
    $aadhar_card = $request->file('aadhar_card');
    $new_name = rand() . '.' . $aadhar_card->getClientOriginalExtension();
    $aadhar_card->move(public_path('aadhar_card'), $new_name);
    $form_data = array(
        'aadhar_card' => $new_name,
    );
    Customer::create($form_data);
    $customer = Customer::create([
        'name' => $request->input('name'),
        'category' => $request->input('category'),
        'mobile_number_1' => $request->input('mobile_number_1'),
        'mobile_number_2' => $request->input('mobile_number_2'),
    ]);

    return redirect('customers.index')->with('success', 'Data added successfully.');
}

This is my create form. There are 5 fillable field 1. name ,2. mobile number 1 ,3. mobile number 2 ,Category and aadhar card.

<form method="post" action="" enctype="multipart/form-data">
        @csrf
        <table>
            <tr>
                <td>Name :</td>
                <td><input type="text" name="name" class="form-control" placeholder="Name"></td>
            </tr>
            <tr>
                <td>Category :</td>
                <td>
                    <select name="category" id="category">
                        <option value="Painter">Painter</option>
                        <option value="Contractor">Contractor</option>
                        <option value="Carpenter">Carpenter</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>Mobile Number 1 :</td>
                <td><input type="text" name="mobile_nubmer_1" class="form-control" placeholder="Mobile Number"></td>
            </tr>
            <tr>
                <td>Mobile Number 2 :</td>
                <td><input type="text" name="mobile_nubmer_2" class="form-control" placeholder="Mobile Number ( Optional )"></td>
            </tr>
            <tr>
                <td>Aadhar Card :</td>
                <td><input type="file" name="aadhar_card" class="form-control"></td>
            </tr>
            <tr><button type="submit" name="submit" id="submit" class="btn btn-primary">Submit</button></tr>
        </table>
    </form>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire