Added checkedOutToUser factory for consumables

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-03 20:18:53 +01:00
parent 4635e9269d
commit d66d6e70a6

View file

@ -7,6 +7,7 @@ use App\Models\Company;
use App\Models\Consumable;
use App\Models\Manufacturer;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Supplier;
@ -116,4 +117,16 @@ class ConsumableFactory extends Factory
$consumable->category->update(['require_acceptance' => 1]);
});
}
public function checkedOutToUser(User $user = null)
{
return $this->afterCreating(function (Consumable $consumable) use ($user) {
$consumable->users()->attach($consumable->id, [
'consumable_id' => $consumable->id,
'created_at' => Carbon::now(),
'user_id' => 1,
'assigned_to' => $user->id ?? User::factory()->create()->id,
]);
});
}
}