CRUD
This commit is contained in:
@ -5,7 +5,7 @@ namespace app\controllers;
|
||||
use app\models\Answer;
|
||||
use app\models\Upvote;
|
||||
|
||||
class Answers {
|
||||
class AnswerController {
|
||||
public function actionAddAnswer($answer,$question_id,$user_id)
|
||||
{
|
||||
return Answer::create(['answer'=>$answer,'question_id'=>$question_id,'user_id'=>$user_id]);
|
@ -3,7 +3,7 @@ namespace app\controllers;
|
||||
|
||||
use app\models\Question;
|
||||
|
||||
class Questions{
|
||||
class QuestionController{
|
||||
public function actionCreateQuestion($question,$user_id)
|
||||
{
|
||||
return Question::create(['question'=>$question,'user_id'=>$user_id]);
|
||||
@ -11,7 +11,7 @@ class Questions{
|
||||
|
||||
public function actionGetQuestionsWithAnswers()
|
||||
{
|
||||
return Question::with('Answers')->get()->toArray();
|
||||
return Question::with('AnswerController')->get()->toArray();
|
||||
}
|
||||
|
||||
public function actionGetQuestionsWithUsers()
|
@ -8,12 +8,17 @@ 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
|
||||
{
|
||||
Debug::dd("create");
|
||||
//return User::create(['username'=>$username,'email'=>$email,'password'=>$password]);
|
||||
require "app/views/userCreate.php";
|
||||
}
|
||||
|
||||
public function actionAdd(): void
|
||||
{
|
||||
User::create($_REQUEST);
|
||||
}
|
||||
|
||||
public function actionQuestionCount($user_id)
|
||||
@ -23,7 +28,6 @@ class UserController {
|
||||
|
||||
public function actionIndex(): void
|
||||
{
|
||||
Debug::dd("list");
|
||||
foreach (User::all() as $user)
|
||||
{
|
||||
echo $user->username . "<br>";
|
||||
@ -32,12 +36,36 @@ class UserController {
|
||||
|
||||
public function actionView($id): void
|
||||
{
|
||||
Debug::dd($id);
|
||||
echo User::where('id', '=', $id)->get();
|
||||
// $user = User::where('id', '=', 13)->get();
|
||||
echo User::where('id', '=', $id)->first() . "<br><br>";
|
||||
|
||||
// echo $user->username . "<br>";
|
||||
// echo $user->email . "<br>";
|
||||
// echo $user->created_at . "<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();
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ namespace app\models;
|
||||
use \Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Answer extends Model {
|
||||
protected $table = 'Answers';
|
||||
protected $table = 'AnswerController';
|
||||
protected $fillable = ['answer','user_id','question_id'];
|
||||
|
||||
public function upvotes()
|
||||
|
@ -5,4 +5,5 @@ use \Illuminate\Database\Eloquent\Model;
|
||||
class User extends Model {
|
||||
protected $table = 'Users';
|
||||
protected $fillable = ['username', 'email', 'password'];
|
||||
protected $dates = ['deleted at'];
|
||||
}
|
||||
|
19
app/views/userCreate.php
Normal file
19
app/views/userCreate.php
Normal file
@ -0,0 +1,19 @@
|
||||
<form action="/admin/user/" method="post">
|
||||
Логин:<br>
|
||||
<label>
|
||||
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
||||
</label> <br> <br>
|
||||
|
||||
Пароль:<br>
|
||||
<label>
|
||||
<input type = "text" name = "password" required size="50" placeholder="Пароль">
|
||||
</label> <br> <br>
|
||||
|
||||
Email адрес: <br>
|
||||
<label>
|
||||
<input type="Email" name="email" required>
|
||||
</label> <br><br>
|
||||
|
||||
<input type = "submit" value="Подтвердить">
|
||||
<input type="reset">
|
||||
</form>
|
24
app/views/userUpdate.php
Normal file
24
app/views/userUpdate.php
Normal file
@ -0,0 +1,24 @@
|
||||
<form action="/admin/user/edit" method="post">
|
||||
id пользователя:<br>
|
||||
<label>
|
||||
<input type = "text" name = "id" required size="50" autofocus placeholder="id">
|
||||
</label> <br> <br>
|
||||
|
||||
Логин:<br>
|
||||
<label>
|
||||
<input type = "text" name = "username" required size="50" autofocus placeholder="Логин">
|
||||
</label> <br> <br>
|
||||
|
||||
Пароль:<br>
|
||||
<label>
|
||||
<input type = "text" name = "password" required size="50" placeholder="Пароль">
|
||||
</label> <br> <br>
|
||||
|
||||
Email адрес: <br>
|
||||
<label>
|
||||
<input type="Email" name="email" required>
|
||||
</label> <br><br>
|
||||
|
||||
<input type = "submit" value="Подтвердить">
|
||||
<input type="reset">
|
||||
</form>
|
Reference in New Issue
Block a user