create(); /** @var Group $group2 */ $group2 = Group::factory()->create(); $model = new Privilege(); $model->name = 'Some Privilege'; $model->description = 'Some long description'; $model->save(); $model->groups()->attach($group1); $model->groups()->attach($group2); /** @var Privilege $savedModel */ $savedModel = Privilege::first(); $this->assertEquals('Some Privilege', $savedModel->name); $this->assertEquals('Some long description', $savedModel->description); $this->assertEquals($group1->name, $savedModel->groups[0]->name); $this->assertEquals($group2->name, $savedModel->groups[1]->name); } }