項目在Laravel 5.3上,我正在爲多個頁面收集會話中的數據,並且我想將它添加到MySQL。問題是數據不會插入到僅限於MySQl的created_at中。數據是可變的,但不會保存在MySQL中。Laravel將數據添加到MySQL
型號:
class Post extends Model
{
public $vardas, $pavarde, $miestas, $amzius, $telefonas, $pastas, $q1, $q2, $q3, $q4;
protected $fillable = ['vardas', 'pavarde', 'miestas', 'amzius', 'telefonas', 'pastas', 'q1', 'q2', 'q3', 'q4'];
public function addToDb($vardas, $pavarde, $miestas, $amzius, $telefonas, $pastas, $q1, $q2, $q3, $q4)
{
$answer = new Post;
$answer->vardas = $vardas;
$answer->pavarde = $pavarde;
$answer->miestas = $miestas;
$answer->amzius = $amzius;
$answer->telefonas = $telefonas;
$answer->pastas = $pastas;
$answer->q1 = $q1;
$answer->q2 = $q2;
$answer->q3 = $q3;
$answer->q4 = $q4;
$answer->save();
}
}
數據庫:
Schema::create('answers', function (Blueprint $table) {
$table->increments('id');
$table->string('vardas');
$table->string('pavarde')->nullable();
$table->string('miestas')->nullable();
$table->string('amzius')->nullable();
$table->string('telefonas')->nullable();
$table->string('pastas')->nullable();
$table->string('q1')->nullable();
$table->string('q2')->nullable();
$table->string('q3')->nullable();
$table->string('q4')->nullable();
$table->timestamps();
});
和控制器:
public function getAciu() {
$vardas = Input::get('vardas');
$pavarde = Input::get('pavarde');
$miestas = Input::get('miestas');
$amzius = Input::get('amzius');
$telefonas = Input::get('telefonas');
$pastas = Input::get('pastas');
$q1 = Session::get('q1');
$q2 = Session::get('q2');
$q3 = Session::get('q3');
$q4 = Session::get('q4');
$answer = new Post;
$answer->addToDb($vardas, $pavarde, $miestas, $amzius, $telefonas, $pastas, $q1, $q2, $q3, $q4);
return view('aciu');
}
你有'使用照亮\數據庫\雄辯\型號;'在模型的頂部? – cssBlaster21895