71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
namespace app\controllers;
|
|
|
|
|
|
use app\helpers\Debug;
|
|
use app\models\Question;
|
|
use app\models\User;
|
|
use http\Encoding\Stream\Debrotli;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class UserController {
|
|
public function actionCreate(): void
|
|
{
|
|
require "app/views/userCreate.php";
|
|
}
|
|
|
|
public function actionAdd(): void
|
|
{
|
|
User::create($_REQUEST);
|
|
}
|
|
|
|
public function actionQuestionCount($user_id)
|
|
{
|
|
return Question::where('user_id', $user_id)->count();
|
|
}
|
|
|
|
public function actionIndex(): void
|
|
{
|
|
foreach (User::all() as $user)
|
|
{
|
|
echo $user->username . "<br>";
|
|
}
|
|
}
|
|
|
|
public function actionView($id): void
|
|
{
|
|
echo User::where('id', '=', $id)->get();
|
|
echo User::where('id', '=', $id)->first() . "<br><br>";
|
|
|
|
$user = User::find($id);
|
|
echo $user->id . "<br>";
|
|
echo $user->username . "<br>";
|
|
echo $user->email . "<br>";
|
|
echo $user->password . "<br>";
|
|
echo $user->created_at . "<br>";
|
|
echo $user->updated_at . "<br>";
|
|
}
|
|
|
|
public function actionUpdate(): void
|
|
{
|
|
Debug::prn("Update");
|
|
require "app/views/userUpdate.php";
|
|
}
|
|
|
|
public function actionEdit(): void
|
|
{
|
|
$user = User::find($_REQUEST['id']);
|
|
$user->username = $_REQUEST['username'];
|
|
$user->email = $_REQUEST['email'];
|
|
$user->password = $_REQUEST['password'];
|
|
$user->save();
|
|
}
|
|
|
|
public function actionDelete($id): void
|
|
{
|
|
User::find($id)->delete();
|
|
}
|
|
|
|
} |