易云巢做网站公司,网站首页的尺寸做多大,贡井区建设局网站,wordpress模板淘宝客模板laravel 自带的批量添加是不会自动维护时间戳的#xff0c;意思是说#xff0c;使用laravel的批量添加#xff0c;时间戳字段不会插入#xff0c;也不会在更新的时候进行更新。
使用继承或者trait来解决这个问题#xff0c;在这里感谢Mr.wen
?php
namespace App\Mo…laravel 自带的批量添加是不会自动维护时间戳的意思是说使用laravel的批量添加时间戳字段不会插入也不会在更新的时候进行更新。
使用继承或者trait来解决这个问题在这里感谢Mr.wen
?php
namespace App\Models\Traits;use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;trait BatchTraits
{public function storeBatch(array $inputs): bool{if (true $this-timestamps) {$time Date::now();foreach ($inputs as $key $value) {if (! is_null(Model::CREATED_AT)) {$inputs[$key][Model::CREATED_AT] $time;}if (! is_null(Model::UPDATED_AT)) {$inputs[$key][Model::UPDATED_AT] $time;}}}$query DB::connection($this-getConnectionName())-table($this-getTable());return $query-insert($inputs);}
}