clrghouz/app/Http/Controllers/EchoareaController.php

44 lines
1.1 KiB
PHP
Raw Normal View History

2021-08-11 13:45:30 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Echoarea;
class EchoareaController extends Controller
{
/**
* Add or edit a echoarea
*/
public function add_edit(Request $request,Echoarea $o)
{
if ($request->post()) {
$this->authorize('admin',$o);
$request->validate([
'domain_id' => 'required|exists:domains,id',
'name' => 'required|min:4|max:35|regex:/^[a-zA-Z0-9\-_~]{4,}$/|unique:echoareas,name,'.($o->exists ? $o->id : 0),
2021-08-11 13:45:30 +00:00
'description' => 'required',
'active' => 'required|boolean',
'show' => 'required|boolean',
'automsgs' => 'required|boolean',
2023-07-29 03:17:36 +00:00
'sec_read' => 'required|integer|min:0|max:7',
'sec_write' => 'required|integer|min:0|max:7',
2021-08-11 13:45:30 +00:00
]);
foreach (['name','description','active','show','notes','domain_id','automsgs'] as $key)
2021-08-11 13:45:30 +00:00
$o->{$key} = $request->post($key);
2023-07-29 03:17:36 +00:00
$o->setRead($request->post('sec_read'));
$o->setWrite($request->post('sec_write'));
2021-08-11 13:45:30 +00:00
$o->save();
return redirect()->to('echoarea');
2021-08-11 13:45:30 +00:00
}
return view('echoarea.addedit')
->with('o',$o);
}
}