diff --git a/app/Http/Controllers/ZoneController.php b/app/Http/Controllers/ZoneController.php index 17babe0..97824e3 100644 --- a/app/Http/Controllers/ZoneController.php +++ b/app/Http/Controllers/ZoneController.php @@ -24,6 +24,15 @@ class ZoneController extends Controller $request->validate([ 'domain_id' => 'required|exists:domains,id', + 'default' => [ + 'required', + 'boolean', + Rule::unique('zones')->where(function ($query) use ($request,$o) { + return $query->where('zone_id',$request->post('zone_id')) + ->where('default',TRUE) + ->where('id','<>',$o->id);; + }) + ], 'zone_id' => [ 'required', 'digits_between:1,5', @@ -59,7 +68,7 @@ class ZoneController extends Controller 'active' => 'required|boolean', ]); - foreach (['zone_id','domain_id','system_id','active','notes','zt_id','zt_ipv4','zt_ipv4_mask','zt_ipv6','zt_ipv6_mask'] as $key) + foreach (['zone_id','default','domain_id','system_id','active','notes','zt_id','zt_ipv4','zt_ipv4_mask','zt_ipv6','zt_ipv6_mask'] as $key) $o->{$key} = $request->post($key); $o->save(); diff --git a/app/Models/Address.php b/app/Models/Address.php index a93e410..620d943 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -273,7 +273,7 @@ class Address extends Model $query->where('domains.name',$domain); }) ->when((! $ftn['d']),function($query) { - $query->where('domains.default',TRUE); + $query->where('zones.default',TRUE); }) ->single(); @@ -296,7 +296,7 @@ class Address extends Model $query->where('domains.name',$domain); }) ->when((! $ftn['d']),function($query) { - $query->where('domains.default',TRUE); + $query->where('zones.default',TRUE); }) ->single(); diff --git a/database/migrations/2021_08_15_134329_default_zones.php b/database/migrations/2021_08_15_134329_default_zones.php new file mode 100644 index 0000000..1d03a5a --- /dev/null +++ b/database/migrations/2021_08_15_134329_default_zones.php @@ -0,0 +1,42 @@ +dropColumn('default'); + }); + + Schema::table('zones', function (Blueprint $table) { + $table->boolean('default')->default(FALSE); + $table->unique(['zone_id','default']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('zones', function (Blueprint $table) { + $table->dropUnique(['zone_id','default']); + $table->dropColumn('default'); + }); + + Schema::table('zones', function (Blueprint $table) { + $table->boolean('default')->default(FALSE); + }); + } +} diff --git a/resources/views/zone/addedit.blade.php b/resources/views/zone/addedit.blade.php index 4ed1dec..367f5a9 100644 --- a/resources/views/zone/addedit.blade.php +++ b/resources/views/zone/addedit.blade.php @@ -50,7 +50,40 @@ -
There are no zones setup, to set up your first.
@@ -29,6 +29,7 @@