{"id":3030,"date":"2022-10-15T14:03:08","date_gmt":"2022-10-15T05:03:08","guid":{"rendered":"https:\/\/took.jp\/?p=3030"},"modified":"2022-12-15T14:53:59","modified_gmt":"2022-12-15T05:53:59","slug":"laravel_updated_at","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/laravel_updated_at\/","title":{"rendered":"\u3010Laravel\u3011\u30c7\u30fc\u30bf\u66f4\u65b0\u6642\u306b\u3001updated_at\u306e\u81ea\u52d5\u66f4\u65b0\u3092\u3057\u306a\u3044\u65b9\u6cd5"},"content":{"rendered":"<h2>\u3010Laravel\u3011\u30c7\u30fc\u30bf\u66f4\u65b0\u6642\u306b\u3001updated_at\u306e\u81ea\u52d5\u66f4\u65b0\u3092\u3057\u306a\u3044\u65b9\u6cd5<\/h2>\n<p>Laravel\u306eEloquent\u30e2\u30c7\u30eb\u306eupdate\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u65e2\u5b58\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3059\u308b\u5834\u5408\u306b\u306f\u3001updated_at\u306e\u6642\u523b\u304c\u81ea\u52d5\u3067\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">$updateParams = ['column' =&gt; 'value'];\r\n$model-&gt;update($updateParams);<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u3092\u81ea\u52d5\u66f4\u65b0\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">$model-&gt;timestamps = false;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u89e3\u6c7a\u3057\u306a\u3044\u5834\u5408<\/h3>\n<p>\u4e0a\u8a18\u3092\u8a18\u8ff0\u3057\u3066\u3082updated_at\u304c\u66f4\u65b0\u3055\u308c\u3066\u3057\u307e\u3046\u5834\u5408\u306b\u306f\u3001MySQL\u5074\u306e\u300cCURRENT_TIMESTAMP ON UPDATE\u300d\u306e\u8a2d\u5b9a\u3067\u81ea\u52d5\u66f4\u65b0\u3055\u308c\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u81ea\u52d5\u66f4\u65b0\u306e\u8a2d\u5b9a\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3059\u308b\u306b\u306f\u3001show columns\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001Extra\u6b04\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-other\">mysql -u root -p\r\nshow columns from [table_name]<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>migration\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9\u3092\u5909\u66f4\u3057\u3066\u3001\u81ea\u52d5\u66f4\u65b0\u3055\u305b\u306a\u3044\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u3044\u308b\u610f\u56f3\u304c\u308f\u304b\u3089\u306a\u3044\u5834\u5408\u306b\u306f\u3001\u4e0b\u8a18\u65b9\u6cd5\u3067\u66f4\u65b0\u3059\u308b\u306e\u304c\u826f\u3044\u306e\u304b\u306a\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">DB::update(update [table_name] set [update_column] = [update_value], updated_at = updated_at where [condition]);<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u300cupdated_at = updated_at\u300d\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u3001updated_at\u3092\u66f4\u65b0\u3055\u305b\u306a\u3044\u3088\u3046\u306b\u3067\u304d\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Laravel\u3011\u30c7\u30fc\u30bf\u66f4\u65b0\u6642\u306b\u3001updated_at\u306e\u81ea\u52d5\u66f4\u65b0\u3092\u3057\u306a\u3044\u65b9\u6cd5 Laravel\u306eEloquent\u30e2\u30c7\u30eb\u306eupdate\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u65e2\u5b58\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3059\u308b\u5834\u5408\u306b\u306f\u3001updated_at\u306e\u6642\u523b\u304c\u81ea\u52d5\u3067\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002 $updat\u2026<\/p>\n","protected":false},"author":3,"featured_media":3031,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-3030","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/3030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=3030"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/3030\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/3031"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=3030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=3030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=3030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}