43 lines
698 B
PHP
43 lines
698 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
use App\Models\User;
|
||
|
|
||
|
class UserController extends Controller
|
||
|
{
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->middleware('can:admin');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Add or edit a node
|
||
|
*/
|
||
|
public function add_edit(Request $request,User $o)
|
||
|
{
|
||
|
if ($request->post()) {
|
||
|
$request->validate([
|
||
|
'email' => 'required|email|unique:users,email,'.($o ? $o->id : NULL),
|
||
|
]);
|
||
|
|
||
|
foreach (['name','email','notes'] as $key)
|
||
|
$o->{$key} = $request->post($key);
|
||
|
|
||
|
$o->save();
|
||
|
|
||
|
return redirect()->action([self::class,'home']);
|
||
|
}
|
||
|
|
||
|
return view('user.addedit')
|
||
|
->with('o',$o);
|
||
|
}
|
||
|
|
||
|
public function home()
|
||
|
{
|
||
|
return view('user.home');
|
||
|
}
|
||
|
}
|