Php 使用模型进行数据库操作时,Laravel dd/mm/yyyy到yyyy/mm/dd/转换
这是我的控制器Php 使用模型进行数据库操作时,Laravel dd/mm/yyyy到yyyy/mm/dd/转换,php,date,laravel,laravel-4,model,Php,Date,Laravel,Laravel 4,Model,这是我的控制器 public function DriverProcess() { $DriverData = Input::all(); $validation = Validator::make($DriverData, DriverModel::$rules); if ($validation->passes()) { DriverModel::create($DriverData)
public function DriverProcess()
{
$DriverData = Input::all();
$validation = Validator::make($DriverData, DriverModel::$rules);
if ($validation->passes())
{
DriverModel::create($DriverData);
//Rest of Code
这是我的型号
<?php
class DriverModel extends Eloquent
{
protected $guarded = array('DriverName');
protected $fillable = array('DriverName', 'Age', 'Address', 'LicenseNumber', 'DateOfBirth', 'LicenseExpiry' );
您可以在您的模型中为此使用变体(请参阅)。在您的情况下,这将是:
public function setDateOfBirthAttribute($value)
{
$this->attributes['DateOfBirth'] = date("Y-m-d", strtotime($value) );
}
作为旁注,您应该只在模型中使用$filleble
或$guarded
。现在,您在$guarded
和$filleble
中设置了相同的属性