<?php namespace App\Http\Controllers; use App\Models\{Role,Permission,Office,OfficeIpRule}; use Illuminate\Http\Request; class SecuritySettingsController extends Controller {public function index(){return view('admin.security',['roles'=>Role::with('permissions')->get(),'permissions'=>Permission::orderBy('slug')->get(),'offices'=>Office::with('ipRules')->get()]);}public function role(Request $r){$d=$r->validate(['name'=>'required|string|max:120','slug'=>'required|string|max:80|unique:roles,slug']);Role::create($d);return back()->with('success','Role created.');}public function sync(Request $r,Role $role){$d=$r->validate(['permissions'=>'array','permissions.*'=>'exists:permissions,id']);$role->permissions()->sync($d['permissions']??[]);return back()->with('success','Role permissions updated.');}public function ip(Request $r){$d=$r->validate(['office_id'=>'required|exists:offices,id','label'=>'required|string|max:120','cidr'=>'required|string|max:64']);OfficeIpRule::create($d+['is_active'=>true]);return back()->with('success','Office IP/CIDR rule added.');}public function deleteIp(OfficeIpRule $rule){$rule->delete();return back()->with('success','IP rule removed.');}}