chuck()
, сейчас с chunkById
быстрее)public function boot()
{
$root = __DIR__.'/../../database/migrations';
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" (>>на которую у него нет прав на чтение)
);
$paths = [$root];
foreach ($iter as $path => $dir) {
if ($dir->isDir()) {
$paths[] = $path;
}
}
$this->loadMigrationsFrom($paths);
}
class Email extends Model
{
use HasFactory;
protected $primaryKey = 'user_id';
public $timestamps = false;
protected $casts = [
'created_at' => 'datetime:Y-m-d',
];
protected $fillable = [
'user_id',
'email',
'add_email_token',
'remove_email_token',
'created_at'
];
}
$data = \App\Models\Email::firstOrNew(
['user_id' => $this->getUserId()],
[
'email' => null,
'add_email_token' => null,
'remove_email_token' => null,
]
);
...
$data->email = $email;
...
$data->save();