I am facing this error while trying to submit my form : General error: 1366 Incorrect integer value : 'important' for column 'importance' at row 1 (SQL: insert into projets (title, dateDebut, dateFin, cout, partenaires_financiers, importance, updated_at, created_at) values (MyTest, 1996/08/15, 1998/06/28, 15900, paldk ksjd, important, 2017-01-18 15:31:57, 2017-01-18 15:31:57))
Here's the code I am using :
submit.blade.php :
<label for="Import">Importance</label>
<div class="form-group">
<label class="radio-inline">
<input type="radio" id="tres_important" name="importance" value="tres_important">Très important</label>
<label class="radio-inline">
<input type="radio" id="important" name="importance" value="important">Important</label>
</div>
the migration "create_projects_table.php" :
class CreateProjetsTable extends Migration
{
public function up()
{
Schema::create('projets', function (Blueprint $table) {
$table->increments('id',true);
$table->string('title');
$table->date('dateDebut');
$table->date('dateFin');
$table->float('cout');
$table->string('partenaires_financiers');
$table->integer('importance');
$table->timestamps();
});
}
"route.php" :
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('/', function () {
$projets = \App\Projet::all();
return view('welcome', compact('projets'));
});
Route::get('/submit', function () {
return view('submit');
});
Route::post('submit/projects', 'Project_Controller@store');
"Project_Controller.php" :
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|max:255',
'dateDebut' => 'required|max:255',
'dateFin' => 'required|max:255',
'cout' => 'required|max:255',
'importance' => 'required',
//'etude' => 'required',
'partenaires_financiers' => 'required',
]);
if ($validator->fails()) {
return back()
->withInput()
->withErrors($validator);
}
$projet = new Projet;
$projet->title = $request->title;
$projet->dateDebut = $request->dateDebut;
$projet->dateFin = $request->dateFin;
$projet->cout = $request->cout;
$projet->partenaires_financiers = $request->partenaires_financiers;
$projet->importance = $request->importance;
$projet->save();
return redirect('/submit');
}
}
I was using this code in my controller before adding the "store" function and it was working :
$create_projets = CreateProjets::find($id);
$data['importance'] = $create_projets->importance;
return view('submit', $data);
I know that the error is caused by the "radio buttons"
Does anyone have an idea how to fixe that please ?