Skip to content

[モデル] モデルの$dates → $castsに切替(Laravel10.xで$date廃止に対応) OW-2518 #2194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/Models/Common/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class Frame extends Model
{
use HasFactory;

// 日付型
protected $dates = [
'content_open_date_from',
'content_open_date_to'
/**
* キャストする必要のある属性
*/
protected $casts = [
'content_open_date_from' => 'datetime',
'content_open_date_to' => 'datetime',
];

/**
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Common/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class Group extends Model
protected $fillable = ['name', 'initial_group_flag', 'display_sequence'];

/**
* 日付型の場合、$dates にカラムを指定しておく。
* キャストする必要のある属性
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [
'deleted_at' => 'datetime',
];

/**
* 特定のページが指定されたときのグループに対する権限。ページ管理で使用。
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Common/GroupUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class GroupUser extends Model
protected $fillable = ['group_id', 'user_id', 'group_role'];

/**
* 日付型の場合、$dates にカラムを指定しておく。
* キャストする必要のある属性
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [
'deleted_at' => 'datetime',
];

/**
* belongsTo 設定
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Common/PageRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class PageRole extends Model
protected $fillable = ['page_id', 'group_id', 'target', 'role_name', 'role_value'];

/**
* 日付型の場合、$dates にカラムを指定しておく。
* キャストする必要のある属性
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $casts = [
'deleted_at' => 'datetime',
];

/**
* ページの系統取得
Expand Down
8 changes: 5 additions & 3 deletions app/Models/Core/UsersLoginHistories.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class UsersLoginHistories extends Model
// 保存時のユーザー関連データの保持(履歴なしUserable)
use UserableNohistory;

// Carbonインスタンス(日付)に自動的に変換
protected $dates = [
'logged_in_at',
/**
* キャストする必要のある属性
*/
protected $casts = [
'logged_in_at' => 'datetime',
];

// 更新する項目の定義
Expand Down
9 changes: 7 additions & 2 deletions app/Models/Migration/Nc3/Nc3Announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Nc3Announcement extends Model
*/
protected $table = 'announcements';

// Carbonインスタンス(日付)に自動的に変換
protected $dates = ['created', 'modified'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'created' => 'datetime',
'modified' => 'datetime',
];
}
9 changes: 7 additions & 2 deletions app/Models/Migration/Nc3/Nc3AuthorizationKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Nc3AuthorizationKey extends Model
*/
protected $table = 'authorization_keys';

/** Carbonインスタンス(日付)に自動的に変換 */
protected $dates = ['created', 'modified'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'created' => 'datetime',
'modified' => 'datetime',
];
}
9 changes: 7 additions & 2 deletions app/Models/Migration/Nc3/Nc3Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class Nc3Frame extends Model
*/
protected $table = 'frames';

// Carbonインスタンス(日付)に自動的に変換
protected $dates = ['created', 'modified'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'created' => 'datetime',
'modified' => 'datetime',
];

/**
* NC3 header_type -> Connect-CMS frame_design 変換用テーブル
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Blogs/BlogsPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ class BlogsPosts extends Model
const read_more_button_default = '続きを読む';
const close_more_button_default = '閉じる';

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];

// 更新する項目の定義
protected $fillable = [
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Blogs/BlogsPostsTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class BlogsPostsTags extends Model
// 保存時のユーザー関連データの保持
use Userable;

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];

/**
* タグデータをポストデータに紐づけ
Expand Down
9 changes: 7 additions & 2 deletions app/Models/User/Calendars/CalendarPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ class CalendarPost extends Model
'contact',
];

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['start_date', 'end_date'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'start_date' => 'datetime',
'end_date' => 'datetime',
];

/**
* 新しいEloqunetコレクションインスタンスの生成
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Contents/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Contents extends Model
'status',
];

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['deleted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'deleted_at' => 'datetime',
];
}
8 changes: 5 additions & 3 deletions app/Models/User/Counters/CounterCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class CounterCount extends Model
'total_count',
];

// Carbonインスタンス(日付)に自動的に変換
protected $dates = [
'counted_at',
/**
* キャストする必要のある属性
*/
protected $casts = [
'counted_at' => 'datetime',
];

/**
Expand Down
9 changes: 7 additions & 2 deletions app/Models/User/Databases/DatabasesInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ class DatabasesInputs extends Model
// 保存時のユーザー関連データの保持(履歴なしUserable)
use UserableNohistory;

// Carbonインスタンス(日付)に自動的に変換
protected $dates = ['posted_at', 'expires_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
'expires_at' => 'datetime',
];

// 更新する項目の定義
protected $fillable = [
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Faqs/FaqsPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class FaqsPosts extends Model
// 保存時のユーザー関連データの保持
use Userable;

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];

// 更新する項目の定義
protected $fillable = ['contents_id', 'faqs_id', 'post_title', 'post_text', 'categories_id', 'posted_at', 'display_sequence', 'status'];
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Faqs/FaqsPostsTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class FaqsPostsTags extends Model
// 保存時のユーザー関連データの保持
use Userable;

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];
}
14 changes: 8 additions & 6 deletions app/Models/User/Forms/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class Forms extends Model
// 保存時のユーザー関連データの保持(履歴なしUserable)
use UserableNohistory;

// Carbonインスタンス(日付)に自動的に変換
protected $dates = [
'display_from',
'display_to',
'regist_from',
'regist_to',
/**
* キャストする必要のある属性
*/
protected $casts = [
'display_from' => 'datetime',
'display_to' => 'datetime',
'regist_from' => 'datetime',
'regist_to' => 'datetime',
];

// 更新する項目の定義
Expand Down
12 changes: 7 additions & 5 deletions app/Models/User/Learningtasks/LearningtasksExaminations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class LearningtasksExaminations extends Model
// 保存時のユーザー関連データの保持(履歴なしUserable)
use UserableNohistory;

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = [
'start_at',
'end_at',
'entry_end_at',
/**
* キャストする必要のある属性
*/
protected $casts = [
'start_at' => 'datetime',
'end_at' => 'datetime',
'entry_end_at' => 'datetime',
];

/**
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Learningtasks/LearningtasksPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class LearningtasksPosts extends Model
use UserableNohistory;
use HasFactory;

// Carbonインスタンス(日付)に自動的に変換
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];

/**
* 課題管理を取得
Expand Down
8 changes: 6 additions & 2 deletions app/Models/User/Learningtasks/LearningtasksPostsFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ class LearningtasksPostsFiles extends Model
// 保存時のユーザー関連データの保持(履歴なしUserable)
use UserableNohistory;

// Carbonインスタンス(日付)に自動的に変換
protected $dates = ['posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'posted_at' => 'datetime',
];

/**
* create()やupdate()で入力を受け付ける ホワイトリスト
Expand Down
8 changes: 5 additions & 3 deletions app/Models/User/Learningtasks/LearningtasksUseSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class LearningtasksUseSettings extends Model
'datetime_value',
];

// Carbonインスタンス(日付)に自動的に変換
protected $dates = [
'datetime_value',
/**
* キャストする必要のある属性
*/
protected $casts = [
'datetime_value' => 'datetime',
];

/**
Expand Down
12 changes: 10 additions & 2 deletions app/Models/User/Opacs/OpacsBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

class OpacsBooks extends Model
{
// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['accept_date', 'storage_life', 'remove_date', 'last_lending_date', 'posted_at'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'accept_date' => 'datetime',
'storage_life' => 'datetime',
'remove_date' => 'datetime',
'last_lending_date' => 'datetime',
'posted_at' => 'datetime',
];

// 更新する項目の定義
protected $fillable = [
Expand Down
10 changes: 8 additions & 2 deletions app/Models/User/Opacs/OpacsBooksLents.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ class OpacsBooksLents extends Model
'delivery_request_time',
];

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['lent_at', 'scheduled_return', 'delivery_request_date'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'lent_at' => 'datetime',
'scheduled_return' => 'datetime',
'delivery_request_date' => 'datetime',
];

/**
* フォーマット付きの返却予定日を返却
Expand Down
8 changes: 7 additions & 1 deletion app/Models/User/Reservations/ReservationsInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class ReservationsInput extends Model
'status',
];

protected $dates = ['start_datetime', 'end_datetime'];
/**
* キャストする必要のある属性
*/
protected $casts = [
'start_datetime' => 'datetime',
'end_datetime' => 'datetime',
];

/**
* 表示する予約日付
Expand Down
3 changes: 0 additions & 3 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class User extends Authenticatable
{
use HasFactory, Notifiable;

// 日付型の場合、$dates にカラムを指定しておく。
protected $dates = ['created_at', 'updated_at'];

// ユーザーの権限セット
public $user_roles = null;

Expand Down