Laravel блейд-форма не отправляет данные формы в базу данных, и ошибка не возвращается - PullRequest
0 голосов
/ 19 июня 2020

У меня есть основная форма c laravel, данные которой не отправляются в данные, но когда я использую echo "<pre>"; print_r($data); die;, я вижу данные в массиве. Кажется, я не понимаю, в чем проблема. Мой контроллер


use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redirect;
use App\Membership;
use Validator;
use Image;
use DB;

class FormController extends Controller
{
    public function register(Request $request){

        if($request->isMethod('post')){
            // $data = $request->all();
            // echo "<pre>"; print_r($data); die;

            $data = request()->validate([
                'title' => 'required',
                'surname' => 'required',
                'firstname' => 'required',
                'middlename' => 'nullable',
                'gender' => 'required',
                'dob' => 'required',
                'maiden_name' => 'required',
                'nationality' => 'required',
                'stateoforigin' => 'required',
                'country' => 'required',
                'marital_status' => 'required',
                'home_address' => 'required',
                'lga' => 'required',
                'state' => 'required',
                'email' => 'required',
                'phone' => 'required',
                'account_num' => 'required',
                'account_name' => 'required',
                'bank_name' => 'required',
                'account_type' => 'required',
                'kinsurname' => 'required',
                'kinfirstname' => 'required',
                'kinmiddlename' => 'nullable',
                'kinaddress' => 'required',
                'relationship' => 'required',
                'kinemail' => 'required',
                'kinphone' => 'required',
                'exists' => 'required',
                'anchor' => 'required',
            ]);

            $membership = new Membership;
            $membership->title = $data['title'];
            $membership->surname = $data['surname'];
            $membership->firstname = $data['firstname'];
            $membership->middlename = $data['middlename'];
            $membership->gender = $data['gender'];
            $membership->dob = $data['dob'];
            $membership->maiden_name = $data['maiden_name'];
            $membership->nationality = $data['nationality'];
            $membership->stateoforigin = $data['stateoforigin'];
            $membership->country = $data['country'];
            $membership->marital_status = $data['marital_status'];
            $membership->home_address = $data['home_address'];
            $membership->lga = $data['lga'];
            $membership->state = $data['state'];
            $membership->email = $data['email'];
            $membership->phone = $data['phone'];
            $membership->account_num = $data['account_num'];
            $membership->account_name = $data['account_name'];
            $membership->bank_name = $data['bank_name'];
            $membership->account_type = $data['account_type'];
            $membership->kinsurname = $data['kinsurname'];
            $membership->kinfirstname = $data['kinfirstname'];
            $membership->kinmiddlename = $data['kinmiddlename'];
            $membership->kinaddress = $data['kinaddress'];
            $membership->relationship = $data['relationship'];
            $membership->kinemail = $data['kinemail'];
            $membership->kinphone = $data['kinphone'];
            $membership->exists = $data['exists'];
            $membership->anchor = $data['anchor'];          
            $membership->save();



            return redirect()->back()->with('flash_message_success','Application submitted successfully!');
        }

        return view('member');

    }
}

Blade:

                            <h3>PERSONAL DETAILS:</h3>
                        <!-- <div class="form-group">
                            <label>Passport</label>
                                <input type="file" name="image">
                        </div> -->
                    <div class="form-group">
                            <label>Title</label>
                                        <select class="form-control" name="title">
                                            <option value="" disabled="disabled" selected="selected">Select Title</option>
                                            <option value="Mr">Mr</option>
                                            <option value="Mrs">Mrs</option>
                                            <option value="Dr">Dr</option>
                                            <option value="Prof">Prof</option>
                                            <option value="Chief">Chief</option>
                                            <option value="Pastor">Pastor</option>
                                            <option value="Reverend">Reverend</option>
                                            <option value="Others">Others</option>
                                        </select>
                        </div>
                        <div class="form-group">
                            <label>Surname</label>
                                <input class="form-control" type="text" name="surname">
                        </div>
                        <div class="form-group">
                            <label>First Name</label>
                            <input class="form-control" type="text" name="firstname">
                        </div>
                        <div class="form-group">
                            <label>Middle Name</label>
                            <input class="form-control" type="text" name="middlename">
                        </div>
                        <div class="form-group">
                        <label>Gender</label>
                            <select class="form-control" name="gender" id="gender">
                                <option value="" disabled="disabled" selected="selected">Select Gender</option>
                                <option value="male">Male</option>
                                <option value="female">Female</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>Date of Birth</label>
                            <input class="form-control" type="text" name="dob">
                        </div>
                        <div class="form-group">
                            <label>Mother's Maiden Name</label>
                            <input class="form-control" type="text" name="maiden_name">
                        </div>
                        <div class="form-group">
                            <label>Nationality</label>
                            <input class="form-control" type="text" name="nationality">
                        </div>
                        <div class="form-group">
                            <label>State of Origin</label>
                            <input class="form-control" type="text" name="stateoforigin">
                        </div>
                        <div class="form-group">
                            <label>Country of Residence</label>
                            <input class="form-control" type="text" name="country">
                        </div>
                        <div class="form-group">
                            <label>Marital Status</label>
                                        <select class="form-control" name="marital_status">
                                            <option value="" disabled="disabled" selected="selected">Select Marital Status</option>
                                            <option value="Single">Single</option>
                                            <option value="Married">Married</option>
                                            <option value="Divorced">Divorced</option>
                                            <option value="Others">Others</option>
                                        </select>
                        </div>

                        <h3>CONTACT DETAILS:</h3>

                        <div class="form-group">
                            <label>Home Address</label>
                            <textarea class="form-control" cols="50" name="home_address"></textarea>
                        </div>
                        <div class="form-group">
                            <label>Local Government Area</label>
                            <input class="form-control" type="text" name="lga">
                        </div>
                        <div class="form-group">
                            <label>State</label>
                            <input class="form-control" type="text" name="state">
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input class="form-control" type="email" name="email">
                        </div>
                        <div class="form-group">
                            <label>Phone</label>
                            <input class="form-control" type="phone" name="phone">
                        </div>

                        <h3>BANK DETAILS:</h3>

                        <div class="form-group">
                            <label>Account Number</label>
                            <input class="form-control" type="phone" name="account_num">
                        </div>
                        <div class="form-group">
                            <label>Account Name</label>
                            <input class="form-control" type="text" name="account_name">
                        </div>
                        <div class="form-group">
                            <label>Bank Name</label>
                            <input class="form-control" type="text" name="bank_name">
                        </div>
                        <div class="form-group">
                        <label>Account Type</label>
                        <select class="form-control" name="account_type" id="account_type">
                            <option value="" selected="selected" disabled="disabled">Select Account Type</option>
                            <option value="savings">Savings</option>
                            <option value="current">Current</option>
                            <option value="fixed">Fixed Deposit</option>
                            <option value="corporate">Corporate</option>
                        </select>
                        </div>

                        <h3>NEXT OF KIN DETAILS:</h3>

                        <div class="form-group">
                            <label>Surname</label>
                            <input class="form-control" type="text" name="kinsurname">
                        </div>
                        <div class="form-group">
                            <label>First Name</label>
                            <input class="form-control" type="text" name="kinfirstname">
                        </div>
                        <div class="form-group">
                            <label>Middle Name</label>
                            <input class="form-control" type="text" name="kinmiddlename">
                        </div>
                        <div class="form-group">
                            <label>Address</label>
                            <textarea class="form-control" type="text" cols="50" name="kinaddress"></textarea>
                        </div>
                        <div class="form-group">
                            <label>Relationship</label>
                            <input class="form-control" type="text" name="relationship">
                        </div>
                        <div class="form-group">
                            <label>Email</label>
                            <input class="form-control" type="email" name="kinemail">
                        </div>
                        <div class="form-group">
                            <label>Phone</label>
                            <input class="form-control" type="phone" name="kinphone">
                        </div>
                        <div class="form-group">
                            <label>Have you ever attempted or benefitted from any Anchor Program before?</label>
                            <select class="form-control" name="exists" id="exists">
                                <option value="" selected="selected" disabled="disabled">Select Answer</option>
                                <option value="yes">Yes</option>
                                <option value="no">No</option>
                            </select>
                        </div>
                        <div class="form-group">
                        <label>If yes, Please state name of anchor/ place</label>
                        <input class="form-control" type="text" name="anchor">
                        </div>
                        <div class="form-group">
                            <input type="submit" class="btn btn-primary" value="Register">
                        </div>
                    </form>

Маршруты:

Route::match(['get','post'], '/register', 'FormController@register');

1 Ответ

0 голосов
/ 20 июня 2020

Проблема была в форме лезвия. Я забыл связать идентификатор с каждым полем ввода.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...