user crud

This commit is contained in:
2024-07-23 15:22:33 +03:00
parent e07448550c
commit d75bc6defe
4 changed files with 104 additions and 61 deletions

View File

@ -7,9 +7,13 @@ use app\helpers\Debug;
use app\models\Question;
use app\models\User;
use app\tables\columns\UserViewActionColumn;
use Exception;
use http\Message;
use Itguild\Tables\ListJsonTable;
use Itguild\Tables\ViewJsonTable;
use kernel\Controller;
use kernel\IGTabel\ListJsonTableEloquentCollection;
use kernel\IGTabel\ViewJsonTableEloquentModel;
use Twig\TwigFunction;
class UserController extends Controller{
@ -54,17 +58,26 @@ class UserController extends Controller{
echo $this->twig->render('user_table.html.twig');
}
/**
* @throws Exception
*/
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->created_at . "<br>";
echo $user->updated_at . "<br>";
if (!$user){
throw new Exception(message: "The user not found");
}
$this->twig->addFunction(new TwigFunction('table', function () use ($user){
$dataProvider = new ViewJsonTableEloquentModel($user, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
]);
$table = new ViewJsonTable($dataProvider->getJson());
$table->create();
$table->render();
}));
echo $this->twig->render('user_table.html.twig');
}
public function actionUpdate(): void