I am a newbie to laravel and I've been trying to grab form input values and submit to the database but i've been having errors. Please i would be happy if you can help me look through it and help check where i am missing the input values.
[2018-11-23 11:20:26] development.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'local_govt_id' cannot be null (SQL: insert into
users_signedups
(state_id
,local_govt_id
,first_name
,surname
,phone_number
,date_of_birth
,title
,education_level_id
,discipline
,work_address
,res_address
,occupation
,gender
,marital_status
,make_donations
,be_a_member
,be_a_volunteer
,about_you
,password
,updated_at
,created_at
) values (1, , , , , , , , , , , , , , , , , , [email protected], , 2018-11-23 11:20:23, 2018-11-23 11:20:23)) {"exception":"[object] (Illuminate\Database\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'local_govt_id' cannot be null (SQL: insert intousers_signedups
(state_id
,local_govt_id
,first_name
,surname
,phone_number
,date_of_birth
,title
,education_level_id
,discipline
,work_address
,res_address
,occupation
,gender
,marital_status
,make_donations
,be_a_member
,be_a_volunteer
,about_you
,password
,updated_at
,created_at
) values (1, , , , , , , , , , , , , , , , , , [email protected], , 2018-11-23 11:20:23, 2018-11-23 11:20:23)) at C:\Users\USER\
my controller is
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//use App\Http\Controllers\Controller;
use App\users_signedup;
class UsersSignedupController extends Controller
{
public function signup(Request $request)
{
return view('signup');
}
public function postUserSignupDetails(Request $request)
{
$validatedData = $request->validate([
'state_id' => 'required',
'local_govt_id' => 'required',
'first_name' => 'required',
'surname' => 'required',
'phone_number' => 'required',
'date_of_birth' => 'required',
'title' => 'required',
'education_level_id' => 'required|numeric',
'discipline' => 'required',
'res_address' => 'required',
'work_address' => 'required',
'occupation' => 'required',
'gender' => 'required|numeric',
'marital_status' => 'required|numeric',
'make_donations' => 'numeric',
'be_a_member' => 'numeric',
'be_a_volunteer' => 'numeric',
'about_you' => 'required',
'email' => 'required|unique:users_signedups',
'password' => 'required'
]);
}
public function store(Request $request)
{
// $users_signedup = $request->session()->get('users_signedup');
$userModel = new users_signedup;
//$userModel = new UserModel;
// dd($request->email);
// $request->state_id
$userModel->state_id = $request->state_id;
$userModel->local_govt_id = $request->local_govt_id;
$userModel->first_name = $request->first_name;
$userModel->surname = $request->surname;
$userModel->phone_number = $request->phone_number;
$userModel->date_of_birth = $request->date_of_birth;
$userModel->title = $request->title;
$userModel->education_level_id = $request->education_level_id;
$userModel->discipline = $request->discipline;
$userModel->work_address = $request->work_address;
$userModel->res_address = $request->res_address;
$userModel->occupation = $request->occupation;
$userModel->gender = $request->gender;
$userModel->marital_status = $request->marital_status;
$userModel->make_donations = $request->make_donations;
$userModel->be_a_member = $request->be_a_member;
$userModel->be_a_volunteer = $request->be_a_volunteer;
$userModel->about_you = $request->about_you;
$userModel->email = $request->email;
$userModel->password = $request->password;
$userModel->save();
return redirect('/signup/success');
}
my model is
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class users_signedup extends Model
{
protected $guarded = [];
}
my view is
<form action="signup/store" method="post">
{{ csrf_field() }}
<div class="col-sm-6">
<div class="form-group">
<select class="form-control" name="state_id" placeholder="Choose your State of Residence" required>
<option value="">Choose your State of Residence</option>
<option value="1">Abia State</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<select class="form-control" name="local_govt_id" placeholder="Choose your Local Government Area" required>
<option value="">Choose your Local Government Area</option>
<option value="1">Umahia</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="first_name" placeholder="First Name" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="surname" placeholder="Surname" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="phone_number" placeholder="Phone" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="date_of_birth" placeholder="Date of Birth" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<select class="form-control" name="title" placeholder="Title" required>
<option value="">Choose your Title</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Ms">Ms</option>
<option value="Miss">Miss</option>
<option value="Prof">Prof</option>
<option value="Chief">Chief</option>
<option value="Dr.">Dr.</option>
<option value="Hon.">Hon.</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="marital_status" placeholder="Marital Status" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<select class="form-control" name="education_level_id" placeholder="Education Level" required>
<option value="">Choose your Education Level</option>
<option value="none">No Education</option>
<option value="primary">Primary</option>
<option value="secondary">Secondary</option>
<option value="tertiary">Tertiary</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="discipline" placeholder="Discipline" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<textarea class="form-control" name="res_address" data-gramm="true" spellcheck="false" data-gramm_editor="true" placeholder="Residential Address" required="required"></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<textarea class="form-control" name="work_address" data-gramm="true" spellcheck="false" data-gramm_editor="true" placeholder="Workplace Address" required="required">
{{ route('signup') }}
{{ csrf_field() }}
</textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="occupation" placeholder="Occupation" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="email" name="email" placeholder="Email" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input class="form-control" type="text" name="password" placeholder="Password" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
{{--<div class="g-recaptcha" data-sitekey="6LfXfnwUAAAAAIJW_OYS6viKZ-ydqSn5_-obFdys"></div>--}}
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
</div>
<button class="sub-btn donate-btn more-btn hvr-shutter-out-horizontal">send</button>
</div>
</form>