clrghouz/app/Http/Controllers/ZoneController.php

59 lines
1.2 KiB
PHP
Raw Normal View History

2021-05-13 12:40:21 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
2021-05-13 12:40:21 +00:00
use App\Models\Zone;
class ZoneController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Add or edit a node
*/
public function add_edit(Request $request,Zone $o)
{
if ($request->post()) {
$this->authorize('admin',$o);
$request->validate([
'domain_id' => 'required|exists:domains,id',
'zone_id' => [
'required',
'digits_between:1,5',
Rule::unique('zones')->where(function ($query) use ($request,$o) {
return $query->where('domain_id',$request->post('domain_id'))
->when($o->exists,function($query) use ($o) {
return $query->where('id','<>',$o->id);
});
})
],
'system_id' => 'required|exists:systems,id',
'ztid' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/',
'active' => 'required|boolean',
]);
foreach (['zone_id','domain_id','system_id','active','notes','ztid'] as $key)
2021-05-13 12:40:21 +00:00
$o->{$key} = $request->post($key);
$o->save();
return redirect()->action([self::class,'home']);
}
return view('zone.addedit')
->with('o',$o);
}
public function home()
{
return view('zone.home');
}
}