I have the following form, this is a simple form with only a single radio button:
@extends('layouts.app')
@section('content')
<h1>Accomodation</h1>
<p>This is the accomodation page.</p>
{!! Form::open(['action' => ['UserController@update', Auth::id()], 'method' => 'POST']) !!}
<div class="form-group">
{{Form::label('ConsiderForAccommodation', 'Consider Me For Accommodation')}}
{{Form::checkbox('ConsiderForAccommodation', 'Consider Me For Accommodation', false)}}
</div>
{!! Form::token() !!}
{{Form::hidden('_method', 'PUT')}}
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
@endsection
I am then trying to update the value "ConsiderForAccomodation" which is a field I added to the users table:
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update(Request $request)
{
// Update the given user
$user = auth()->user();
$user->ConsiderForAccommodation = $request->input('ConsiderForAccommodation');
$user->save();
return redirect('/accommodation');
}
However, upon checking the box and then submitting the form, I am given this error:
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'Consider Me For Accommodation' for column 'ConsiderForAccommodation' at row 1 (SQL: update `users` set `updated_at` = 2019-03-18 20:44:37, `ConsiderForAccommodation` = Consider Me For Accommodation where `id` = 1)
It seems to be reaching this update method, however, I seem to be doing something wrong as it's not picking up the value of the checkbox.
What am I doing wrong? If more of the code is required I'll be happy to update the post.
EDIT - User table migration, looking in MySQL the column has been created as a "TinyInt" which as far as I know is the correct type:
class UserAddAccomodationFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Add field "ConsiderForAccommodation" to table.
Schema::table('users', function(Blueprint $table)
{
$table->boolean('ConsiderForAccommodation');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Remove field "ConsiderForAccommodation" from table.
Schema::table('users', function(Blueprint $table)
{
$table->dropColumn('ConsiderForAccommodation');
});
}
}
Form::checkboxis, but it looks like it's setting the value of$request->input("ConsiderForAccommodation")toConsider me for Accommodation$request->input("ConsiderForAccommodation");shows that it contains literally that string. Check your source code; (right click your checkbox and inspect element), you'll probably see<input type="checkbox" name="ConsiderForAccommodation" value="Consider Me For Accommodation"/>(or similar).