I am in the way of learning laravel and at this point I am trying to send a query back to my database from a basic from that i build using CoreUI as an admin template.
So basically i get this error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstName' cannot be null (23000)
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstName' cannot be null (SQL: insert into `clients` (`firstName`, `lastName`, `companyName`, `phone`, `email`, `password`, `address1`, `address2`, `city`, `postcode`, `country`, `notes`, `updated_at`, `created_at`) values (, , , , , , , , , , , , 2020-10-19 01:41:04, 2020-10-19 01:41:04))
Previous exceptions
and my clientscontroller.php includes this code
use App\Client;
public function store(Request $req){
$client = new Client;
$client->firstName = $req->firstName;
$client->lastName = $req->lastName;
$client->companyName = $req->companyName;
$client->phone = $req->phone;
$client->email = $req->email;
$client->password = $req->password;
$client->address1 = $req->address1;
$client->address2 = $req->address2;
$client->city = $req->city;
$client->postcode = $req->postcode;
$client->country = $req->country;
$client->notes = $req->notes;
$client->save();
return redirect('addclient')->with('status','Client added successfully!');
}
in my model client.php i have include nothing because i seen 20 tutorials but nowhere i could able to find what should i do so i have just included those 2
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
the routes i think are correct so does anyone knows what do i miss because on the web there is no clear way of sending data from the blade to the mysql.
Thanks a lot!
EDIT:
Here is the form:
<h4 class="card-title">Add new Client</h4>
<p class="card-description">Enter customer information</p>
<form action="{{route('save')}}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="firstName">First Name</label>
<input type="text" class="form-control" id="firstName" placeholder="John">
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" placeholder="Doe">
</div>
<div class="form-group">
<label for="companyName">Company Name</label>
<input type="text" class="form-control" id="companyName" placeholder="WEBSUNRISE">
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="text" class="form-control" id="phone" placeholder="+44.7545958574">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" placeholder="[email protected]">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="••••••••">
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Submit</button>
</div>
</div>
</div>
</div>
$req->firstName;to$req->input('firstName');and do the same for all of the other inputs. - bassxzerodd()to check if either$req->firstNameor$client->firstNameis set correctly as you sent on the request. - dustinmwang2104dd($req->firstName)at the first line ofstoremethod and see the result. - dustinmwang2104