DEV Community

Mahmoud Ramadan
Mahmoud Ramadan

Posted on

πŸ’‘ Two Lesser-Known Laravel Tricks: numerify & invisible

Laravel is full of hidden gems that can make your development smoother. Today, I want to highlight two handy features you might not know about:


1️⃣ numerify in Eloquent Factories

The numerify method from Faker lets you replace # characters with random digits.

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

2️⃣ invisible in Migrations

The invisible column modifier hides a column from default SELECT queries while keeping it in the database.

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

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

πŸš€ Find more tips and share your knowledge here:
https://github.com/digging-code-blog

Top comments (0)