I want to create a new user, this is my view:
<form enctype="multipart/form-data" action="/user/create" method="POST">
<label>Naam</label>
<input type="text" name="name" id="name">
<label>Email</label>
<input type="text" name="email" id="email">
<label>Password</label>
<input type="text" name="password" id="password">
<label>Admin</label>
<input type="checkbox" name="admin" id="admin"><label for="admin">Admin</label>
<label>Safety Settings</label>
<input type="checkbox" name="watchDashboard" id="watchDashboard"><label for="watchDashboard">Watch Dashboard</label><br>
<input type="checkbox" name="watchBlocks" id="watchBlocks"><label for="watchBlocks">Watch Blocks</label>
<input type="checkbox" name="editBlocks" id="editBlocks"><label for="editBlocks">Edit Blocks</label>
<input type="checkbox" name="watchWastes" id="watchWastes"><label for="watchWastes">Watch Wastes</label>
<input type="checkbox" name="editWastes" id="editWastes"><label for="editWastes">Edit Wastes</label>
<input type="checkbox" name="watchGrondstof" id="watchGrondstof"><label for="watchGrondstof">Watch Grondstof</label>
<input type="checkbox" name="editGrondstof" id="editGrondstof"><label for="editGrondstof">Edit Grondstof</label>
<input type="checkbox" name="manageUsers" id="manageUsers"><label for="manageUsers">Manage Users</label>
{{ csrf_field() }}
<input type="submit" class="pull-right btn btn-sm btn-primary">
</form>
When I hit submit button, I want to get the data in my database:
public function create(Request $request){
$user = new User();
$user::create(
$request->all()
);
}
When I hit submit I get this error:
General error: 1366 Incorrect integer value: 'on' for column.
How can I make sure when I do $request->all()
that the on value is true or 1?
Thanks!
How about modifying the data before passing it to the model?
public function create(Request $request){
$data = $request->all();
$data['watchDashboard'] = $request->watchDashboard ? 1 : 0;
$data['watchBlocks'] = $request->watchBlocks? 1 : 0;
..... (other checkboxes)
$user = new User();
$user::create($data);
}
Didn't try it but that was the idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With