💡 两个不太为人知的 Laravel 技巧:numerify 与 invisible

发布: (2025年12月12日 GMT+8 06:18)
1 min read
原文: Dev.to

Source: Dev.to

Eloquent 工厂中的 numerify

Fakernumerify 方法可以将 # 字符替换为随机数字。

public function definition(): array
{
    return [
        'phone' => $this->faker->numerify('+##'), // Example output: +20
    ];
}

迁移中的 invisible

invisible 列修饰符会在默认的 SELECT 查询中隐藏该列,但仍保留在数据库中。

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

Schema::create('users', function (Blueprint $table) {
    $table->timestamp('email_verified_at')
          ->nullable()
          ->invisible();
});

在此获取更多技巧并分享您的知识:
https://github.com/digging-code-blog

Back to Blog

相关文章

阅读更多 »