Laravel : How do I insert the first user in the database

I’m doing it this way: creating seeder with artisan: php artisan make:seeder UsersTableSeeder then you open the file and you enter users: use Illuminate\Database\Seeder; class UsersTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::table(‘users’)->insert([ ‘name’ => ‘User1′, ’email’ => ‘user1@email.com’, ‘password’ => bcrypt(‘password’), ]); … Read more

How to seed database migrations for laravel tests?

All you need to do is make an artisan call db:seed in the setUp function <?php use Illuminate\Foundation\Testing\DatabaseMigrations; class ExampleTest extends TestCase { use DatabaseMigrations; public function setUp(): void { parent::setUp(); // seed the database $this->artisan(‘db:seed’); // alternatively you can call // $this->seed(); } /** * A basic functional test example. * * @return void … Read more

Laravel – Seeding Many-to-Many Relationship

You can use attach() or sync() method on a many-to-many relationship. There are multiple ways you can approach this. Here one of them: // Populate roles factory(App\Role::class, 20)->create(); // Populate users factory(App\User::class, 50)->create(); // Get all the roles attaching up to 3 random roles to each user $roles = App\Role::all(); // Populate the pivot table … Read more

How to pass arguments to Laravel factories?

The attributes you pass to the create function will be passed into your model definition callback as the second argument. In your case you don’t even need to access those attributes, since they’ll automatically be merged in: $business = factory(App\Business::class)->create(); factory(App\User::class, 5)->create([ ‘business_id’ => $business->id, ]); Adapt this to your needs.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)