Why does Laravel 5 auto update my date field?
<p>I want to update a field (<code>status</code>) on the model. I would retrieve from DB and assign a new value to <code>status</code> column. But after the model saved, I saw another date field (<code>published_at</code>) also changed to same as <code>updated_at</code>.
The action run when user click on a link as <a href="http://localhost:8097/dashboard/gallery/publish/1" rel="noreferrer">http://localhost/dashboard/gallery/publish/1</a>.</p>

<p>I don't know why the <code>published_at</code> updated auto and same as <code>updated_at</code>? </p>

<p>Here is <strong>Controller code</strong>:</p>

<pre><code>&lt;?php 
class GalleryController extends Controller
{
    /**
     * Approve to publish the gallery on the web.
     *
     * @param  int  $id
     * @return Response
     */
    public function getPublish($id)
    {
        $gallery = Gallery::whereId($id)-&gt;firstOrFail();       
        $gallery-&gt;status = Gallery::STT_PUBLISH;
        $gallery-&gt;save();
        return redirect( route('backend::gallery.edit',[$gallery-&gt;id]) )-&gt;with('status', 'Done');
    }
}
?&gt;
</code></pre>

<p>and <strong>Gallery Model</strong>:</p>

<pre><code>&lt;?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Gallery extends Model
{
  use SoftDeletes;
  protected $table = 'gallery';
  protected $fillable = ['title', 'slug', 'content', 'category_id', 'type'];
  protected $guarded = ['published_at','creator_id','thumbnail'];
  protected $dates = ['deleted_at', 'published_at'];
}
?&gt;
</code></pre>

<p>and <strong>Migration func</strong>:</p>

<pre><code>public function up()
    {
        Schema::create('gallery', function (Blueprint $table) {
            $table-&gt;increments('id')-&gt;unsigned();
            $table-&gt;string('slug')-&gt;unique();   
            $table-&gt;tinyInteger('type')-&gt;unsigned();
            $table-&gt;integer('category_id')-&gt;unsigned()-&gt;default(0); 
            $table-&gt;string('thumbnail');   
            $table-&gt;string('title');   
            $table-&gt;text('content');
            $table-&gt;integer('status')-&gt;unsigned()-&gt;default(0);
            $table-&gt;timestamp('published_at');
            $table-&gt;integer('creator_id')-&gt;unsigned();
            $table-&gt;timestamps();            
            $table-&gt;index(['slug']);
            $table-&gt;softDeletes();
        });
        Schema::table('gallery', function (Blueprint $table) {
            $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('category');
            $table-&gt;foreign('creator_id')-&gt;references('id')-&gt;on('users');
        });
    }
</code></pre>

<p><strong>UPDATE</strong></p>

<p>I see this config in Migration function makes problem, here:
<code>$table-&gt;timestamp('published_at');</code></p>

<p>And this statement creates SQL like that:</p>

<pre><code>CREATE TABLE `gallery` ( 
    ...
     `published_at` Timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    ...
)
</code></pre>

<p>So, how to set up a timestamp field, which is not auto update on current time?</p>

<p><strong>UPDATE 2</strong></p>

<p>Done, I modify the migration, just use <code>dateTime</code> instead of <code>timestamp</code>.</p>

<p>Use it, <code>$table-&gt;dateTime('published_at');</code>, this statement will not auto update on CURRENT_TIMESTAMP.</p>