【发布时间】:2015-05-23 21:00:28
【问题描述】:
我想将一个问题(文本)放入我的数据库。将表连同创建的ID和时间放入数据库,但问题(文本)仍然是空的。
(不要注意Question1/2/3/4,这些还没有进入数据库,所以只是关于“测验名称”)
这是我的代码:
public function postCreate() {
$validator = Validator::make(Input::all(), Quiz::$rules);
if($validator->passes()) {
$quiz = new Quiz;
$quiz->quizname = Input::get('quizname');
$quiz->save();
return Redirect::to('quizzes')->with('message', 'Your quiz has been created!');
}
{{ Form::open(array('url'=>'quizzes/create', 'class' => 'createquiz')) }}
<h2>Create a Quiz now!</h2>
<p>Quiz Name</p>{{ Form::text('quizname', null, array('required')) }}
<p>Question 1</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 1', 'size' => '40')) }}
<p>Question 2</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 2', 'size' => '40')) }}
<p>Question 3</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 3', 'size' => '40')) }}
<p>Question 4</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 4', 'size' => '40')) }}
<br>
<br>
{{ Form::button('Add Question') }}
{{ Form::submit('Create') }}
{{ Form::close() }}
public function up()
{
Schema::create('quizzes', function($table)
{
$table->increments('id');
$table->string('quizname');
$table->date('created_at');
$table->dateTime('updated_at');
});
Schema::table('quizzes', function($table)
{
});
}
【问题讨论】:
-
使用 var_dump(Input::get('quizname'));看看你是否得到了输入。如果那是空的,那就是你问题的根源。这很可能与@user3158900 提到的内容有关。
标签: php laravel laravel-4 blade