Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2020-11-03 17:18:31 +01:00
<?php
namespace Database\Factories;
use App\Models\Ipv4Address;
2021-07-13 16:35:43 -05:00
use App\Models\Ipv4Network;
use App\Models\Port;
2020-11-03 17:18:31 +01:00
use Illuminate\Database\Eloquent\Factories\Factory;
use LibreNMS\Util\IPv4;
2021-07-26 16:00:34 +02:00
/** @extends Factory<Ipv4Address> */
2020-11-03 17:18:31 +01:00
class Ipv4AddressFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Ipv4Address::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$prefix = $this->faker->numberBetween(0, 32);
$ip = new IPv4($this->faker->ipv4() . '/' . $prefix);
2020-11-03 17:18:31 +01:00
return [
'ipv4_address' => $ip->uncompressed(),
'ipv4_prefixlen' => $prefix,
'port_id' => function () {
2021-07-13 16:35:43 -05:00
$port = Port::factory()->create(); /** @var Port $port */
return $port->port_id;
2020-11-03 17:18:31 +01:00
},
'ipv4_network_id' => function () use ($ip) {
2021-07-13 16:35:43 -05:00
$ipv4 = Ipv4Network::factory()->create(['ipv4_network' => $ip->getNetworkAddress() . '/' . $ip->cidr]); /** @var Ipv4Address $ipv4 */
return $ipv4->ipv4_network_id;
2020-11-03 17:18:31 +01:00
},
];
}
}