74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\FolderVisibility;
|
|
use App\Models\Folder;
|
|
use App\Models\Organization;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<Folder>
|
|
*/
|
|
class FolderFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'name' => fake()->unique()->words(2, true),
|
|
'color' => fake()->optional()->randomElement(Folder::COLORS),
|
|
'parent_id' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the folder belongs under the given parent folder.
|
|
*/
|
|
public function childOf(Folder $folder): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'parent_id' => $folder->id,
|
|
'user_id' => $folder->user_id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the folder sits in the given organization, inheriting the
|
|
* visibility the workspace defaults to.
|
|
*/
|
|
public function inOrganization(Organization $organization): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'organization_id' => $organization->id,
|
|
'visibility' => Folder::defaultVisibilityFor($organization->id),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the folder is shared with everyone in its workspace.
|
|
*/
|
|
public function sharedWithWorkspace(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'visibility' => FolderVisibility::Workspace,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the folder is only visible to people it is shared with.
|
|
*/
|
|
public function private(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'visibility' => FolderVisibility::Private,
|
|
]);
|
|
}
|
|
}
|