duanliu6083
2016-07-25 07:07
浏览 207
已采纳

在laravel中将后期数据保存到数据库

I Wanna save post data in Laravel. This is my code:

public function addContact(Request $request){
    $contact = new Contact();
    $contact->addContact($request);
    return back();
}

and in the Model:

public function addContact($contactData){
       return $this->save($contactData);
}

it's saves in the database but the data in it is NOT save. saves like an empty row. if I change it to this, it's working:

public function addContact($contactData){
      $this->user_id = $contactData->user_id;
      $this->text = $contactData->text;
      return $this->save();
}

Why the first one is not working?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题