我在尝试提交表单时遇到此错误:常规错误:1366错误的整数值:第1行的列'重要性'为'重要'(SQL:插入到projets中(title,dateDebut,dateFin,cout,partenaires_financiers) ,important,updated_at,created_at)值(MyTest,1996/08 / 15,1998 / 06 / 28,15900,paldk ksjd,重要,2017-01-18 15:31:57,2017-01-18 15:31: 57))
这是我正在使用的代码:
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>
迁移“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');
}
}
我在添加“store”功能之前在我的控制器中使用了这段代码,它正在运行:
$create_projets = CreateProjets::find($id);
$data['importance'] = $create_projets->importance;
return view('submit', $data);
我知道错误是由“单选按钮”引起的
有没有人知道如何解决这个问题?
答案 0 :(得分:0)
在您想要更改的create_projects_table
$table->integer('importance');
来
$table->string('importance');
或者如果重要性是二进制值,如0/1
$projet->importance = $request->importance === 'important' ? 1 : 0;
如果选择的收音机很重要,则将重要性指定为1。 (不确定tres是否重要或多或少)