user crud
This commit is contained in:
@ -50,6 +50,8 @@ class UserController extends Controller{
|
||||
$this->redirect("/admin/user/create");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function actionQuestionCount($user_id)
|
||||
{
|
||||
return Question::where('user_id', $user_id)->count();
|
||||
@ -99,41 +101,36 @@ class UserController extends Controller{
|
||||
*/
|
||||
public function actionUpdate($id): void
|
||||
{
|
||||
$this->cgView->render("user/form.php");
|
||||
$model = User::find($id);
|
||||
if (!$model){
|
||||
throw new Exception(message: "The user not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("user/form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
// $_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
|
||||
//
|
||||
// $user = User::find($_REQUEST['id']);
|
||||
// $user->username = $_REQUEST['username'];
|
||||
// $user->email = $_REQUEST['email'];
|
||||
// $user->password_hash = $_REQUEST['password_hash'];
|
||||
// $user->save();
|
||||
|
||||
// $user = User::find($id);
|
||||
// if (!$user){
|
||||
// throw new Exception(message: "The user not found");
|
||||
// }
|
||||
// $userForm = new CreateUserForm();
|
||||
// $userService = new UserService();
|
||||
// $userForm->load($_REQUEST);
|
||||
//// Debug::prn($userForm->validate());
|
||||
//// Debug::dd($userForm->getErrors());
|
||||
// if ($userForm->validate()){
|
||||
//// Debug::prn($userService);
|
||||
//
|
||||
// $userService->create($userForm);
|
||||
// $this->redirect("/admin/user/" . User::find($id)['id']);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $this->redirect("/admin/user/update/" . $id);
|
||||
// }
|
||||
$user = User::find($id);
|
||||
if (!$user){
|
||||
throw new Exception(message: "The user not found");
|
||||
}
|
||||
$userForm = new CreateUserForm();
|
||||
$userService = new UserService();
|
||||
$userForm->load($_REQUEST);
|
||||
if ($userForm->validate()){
|
||||
$user = $userService->update($userForm, $user);
|
||||
if ($user){
|
||||
$this->redirect("/admin/user/" . $user->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/user/update/" . $id);
|
||||
}
|
||||
|
||||
public function actionDelete($id): void
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
User::find($id)->delete();
|
||||
$this->redirect("/admin/user/");
|
||||
|
Reference in New Issue
Block a user