简体   繁体   English

laravel5 中的日期数据类型更新

[英]Date datatype updation in laravel5

i am updating data posted from form.我正在更新从表单发布的数据。 one of the column is of datatime datatype in mysql.其中一列是mysql中的数据时间数据类型。

All the data is updating except the Datetime column.除日期时间列外,所有数据都在更新。

My code is as below我的代码如下

DB::table('CANDIDATE')
->where('CANDIDATEID',$ID)
->update(
        [
        'fname'=>$fname
        ,'mname'=>$mname
        ,'lname'=>$lname
        ,'genderid'=>$GENDERID
        ,'dob'=>$dob
        ,'address'=>$address
        ,'city'=>$city
        ,'pinno'=>$pinno
        ,'statesid'=>$STATESID
        ,'countryid'=>$COUNTRYID
        ,'contactno'=>$contactno
        ,'industryprtid'=>$INDUSTRYPRTID
        ,'cur_prof_titl'=>$cur_prof_titl
        ,'skills'=>$skills
        ,'certificate'=>$certificate
        ,'emp_typeid'=>$EMPTYPEID
        ,'experienceid'=>$EXPERIENCEID
        ,'educationid'=>$EDUCATIONID
        ,'edu_major'=>$edu_major
        ,'other_detail'=>$other_detail
        ,'mainobj'=>$mainobj
        ,'relocate'=>$relocate
        ,'sal_rngid'=>$sal_rngid
        ]

);

What is wrong in the code.代码有什么问题。

Laravel does not set the timestamps when you're using the fluent builder instead of using Eloquent.当您使用 fluent builder 而不是使用 Eloquent 时,Laravel 不会设置时间戳。 So you'll need a model for this.所以你需要一个模型。

Fluent builder will not set timestamps Fluent builder 不会设置时间戳

DB::table('CANDIDATE')
    ->where('CANDIDATEID', $ID)
    ->update(
    // ...

Eloquent model will: Eloquent 模型将:

<?php namespace App\Namespace;

use Illuminate\Database\Eloquent\Model;

class Candidate extends Model
{
    // Model foo here
}

And then use:然后使用:

App\Namespace\Candidate::where('CANDIDATEID, $ID)
    ->update(
    // ...

Given that you do have the default laravel timestamp columns available in your table.鉴于您的表中确实有默认的 laravel 时间戳列可用。 (created_at, updated_at). (created_at,updated_at)。


Unrelated, but worth mentioning:无关,但值得一提:

If/when possible, check your naming convention, it will be easier to follow the Laravel naming convention for table and column names (eg use candidates as table name and candidate_id for column names.)如果/当可能的话,请检查您的命名规则,这将是更容易遵循表和列名的Laravel命名约定(如使用candidates作为表名和candidate_id列名。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM