namespace App\Http\Livewire; use Livewire\Component; use App\Models\FirewallRule; // Add the FirewallRule model to interact with the database class AccessControlRules extends Component { public $ip_address; public $action = 'allow'; public $description; public $type = 'blacklist'; // Default tab set to blacklist // Method to render the component with firewall rules based on type public function render() { // Fetch rules based on the current tab (blacklist/whitelist) $rules = FirewallRule::where('type', $this->type)->get(); return view('livewire.access-control-rules', compact('rules')); } // Method to set the tab type (blacklist or whitelist) public function setType($type) { $this->type = $type; } // Method to handle adding a new rule public function addRule() { // Validation can be added here if necessary FirewallRule::create([ 'ip_address' => $this->ip_address, 'action' => $this->action, 'description' => $this->description, 'type' => $this->type, // Ensure the rule is assigned to the current tab type ]); // Reset the form after submission $this->reset(['ip_address', 'action', 'description']); session()->flash('message', 'Firewall rule added successfully!'); } }