Disable Laravel's Eloquent timestamps

后端 未结 10 1488
余生分开走
余生分开走 2020-12-04 08:54

I\'m in the process of converting one of our web applications from CodeIgniter to Laravel. However at this moment we don\'t want to add the updated_at / c

10条回答
  •  青春惊慌失措
    2020-12-04 09:29

    Simply place this line in your Model:

    public $timestamps = false;

    And that's it!


    Example:


    To disable timestamps for one operation (e.g. in a controller):

    $post->content = 'Your content'; 
    $post->timestamps = false; // Will not modify the timestamps on save
    $post->save();
    

    To disable timestamps for all of your Models, create a new BaseModel file:

    Then extend each one of your Models with the BaseModel, like so:

提交回复
热议问题