问答详情
源自:2-4 Laravel-通过表单实现新增及操作状态提示功能

为什么新增数据的created_at没有自动维护

class Student extends Model

{

protected $table = 'student';


public $timestamps = true;


protected function getDateFromat()

{

return time();

}


protected function asDateTime($val)

{

return $val;

}

}


public function save(Request $request)

{

$data = $request->input('Student');

//var_dump($data);

$students = new Student();

$students->name = $data['name'];

$students->age = $data['age'];

$students->sex = $data['sex'];

//$student->save();

if($students->save()){

return redirect('student/index');

}else{

return redirect()->back();

}

}


提问者:qq_春秋入我心_gjpv16 2018-10-20 18:55

个回答

  • 渗透_
    2019-11-19 11:03:56

    getDateFromat改getDateFormat

  • L_yeluo
    2018-10-25 12:04:44

    protected function getDateFromat() 改成 public  function getDateFromat() 试试?