2023-09-10 12:48:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
2024-05-25 12:25:57 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
2023-09-10 12:48:12 +00:00
|
|
|
|
2024-05-25 12:25:57 +00:00
|
|
|
use App\Models\{Domain,Echoarea};
|
2023-09-10 12:48:12 +00:00
|
|
|
|
|
|
|
class DomainRequest extends FormRequest
|
|
|
|
{
|
|
|
|
public function authorize(Domain $o)
|
|
|
|
{
|
2024-04-25 05:27:45 +00:00
|
|
|
return Gate::allows('admin',$o);
|
2023-09-10 12:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(Request $request)
|
|
|
|
{
|
|
|
|
if (! $request->isMethod('post'))
|
|
|
|
return [];
|
|
|
|
|
|
|
|
$o = $this->route('o');
|
|
|
|
|
|
|
|
return [
|
2024-05-29 08:59:44 +00:00
|
|
|
'name' => [
|
|
|
|
'required',
|
|
|
|
'max:8',
|
|
|
|
'regex:/^[a-z-_~]{1,8}$/',
|
|
|
|
Rule::unique('domains')
|
|
|
|
->where(fn($query)=>$query
|
|
|
|
->where('name',$request->post('name'))
|
|
|
|
->when($o?->exists,fn($query)=>$query->where('id','<>',$o->id))
|
|
|
|
)
|
|
|
|
],
|
|
|
|
'dnsdomain' => [
|
|
|
|
'nullable',
|
|
|
|
'regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
|
|
|
|
Rule::unique('domains')
|
|
|
|
->where(fn($query)=>$query
|
|
|
|
->where('dnsdomain',$request->post('dnsdomain'))
|
|
|
|
->when($o?->exists,fn($query)=>$query->where('id','<>',$o->id))
|
|
|
|
)
|
|
|
|
],
|
2023-09-10 12:48:12 +00:00
|
|
|
'active' => 'required|boolean',
|
|
|
|
'public' => 'required|boolean',
|
2024-04-26 06:18:40 +00:00
|
|
|
'accept_app' => 'required|boolean',
|
2023-09-10 12:48:12 +00:00
|
|
|
'flatten' => 'nullable|boolean',
|
2024-05-25 12:25:57 +00:00
|
|
|
'nodestatus_id' => [
|
|
|
|
'nullable',
|
|
|
|
Rule::exists(Echoarea::class,'id'),
|
|
|
|
Rule::in($o->echoareas->pluck('id')),
|
|
|
|
]
|
2023-09-10 12:48:12 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|