A really simple trick I’ve been doing for some time now is adding my own account to my UsersTableSeeder when I develop any application that uses authentication.

This trick is great for helping other developers who come on board because there’s no messing around with the database or having to remember a password set by someone else. This is especially good as being dyslexic myself I rarely remember passwords created by myself let alone others.

So, first what we’re going to do is simply add three lines to our .env and .env.example files (don’t put your actual password in a .env.example of course). Put double quotes around the name so it can handle any spaces correctly.

Now we can simply make the UsersTableSeeder class. First run php artisan make:seeder UsersTableSeeder to create the file. Then we add the following to the run method:

The factory for the User should already exist in a default Laravel project so this will do the majority of the work for us. Please note that we put default values as the second argument to the env() function. This is done so that it doesn’t break the seeding if one of our new environment variables are missing from .env. Don’t forget to then change the DatabaseSeeder class in the seeds folder as UserTableSeeder will be commented out by default. Oh and if you don’t realise, both the Hash facade and App\User model will need to be imported in our UserTableSeeder.