migration up
This commit is contained in:
parent
70b2f7e5cc
commit
3df81597b6
@ -4,9 +4,9 @@ namespace app\controllers;
|
|||||||
use app\models\Question;
|
use app\models\Question;
|
||||||
|
|
||||||
class QuestionController{
|
class QuestionController{
|
||||||
public function actionCreateQuestion($question,$user_id)
|
public function actionCreate()
|
||||||
{
|
{
|
||||||
return Question::create(['question'=>$question,'user_id'=>$user_id]);
|
require "app/views/questionCreate.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionGetQuestionsWithAnswers()
|
public function actionGetQuestionsWithAnswers()
|
||||||
|
@ -5,10 +5,6 @@ namespace app\controllers;
|
|||||||
use app\helpers\Debug;
|
use app\helpers\Debug;
|
||||||
use app\models\Question;
|
use app\models\Question;
|
||||||
use app\models\User;
|
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 {
|
class UserController {
|
||||||
public function actionCreate(): void
|
public function actionCreate(): void
|
||||||
@ -18,6 +14,7 @@ class UserController {
|
|||||||
|
|
||||||
public function actionAdd(): void
|
public function actionAdd(): void
|
||||||
{
|
{
|
||||||
|
$_REQUEST["password_hash"] = password_hash($_REQUEST["password_hash"], PASSWORD_DEFAULT);
|
||||||
User::create($_REQUEST);
|
User::create($_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +40,6 @@ class UserController {
|
|||||||
echo $user->id . "<br>";
|
echo $user->id . "<br>";
|
||||||
echo $user->username . "<br>";
|
echo $user->username . "<br>";
|
||||||
echo $user->email . "<br>";
|
echo $user->email . "<br>";
|
||||||
echo $user->password . "<br>";
|
|
||||||
echo $user->created_at . "<br>";
|
echo $user->created_at . "<br>";
|
||||||
echo $user->updated_at . "<br>";
|
echo $user->updated_at . "<br>";
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace app\models;
|
|||||||
use \Illuminate\Database\Eloquent\Model;
|
use \Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Answer extends Model {
|
class Answer extends Model {
|
||||||
protected $table = 'AnswerController';
|
protected $table = 'answer';
|
||||||
protected $fillable = ['answer','user_id','question_id'];
|
protected $fillable = ['answer','user_id','question_id'];
|
||||||
|
|
||||||
public function upvotes()
|
public function upvotes()
|
||||||
|
@ -4,6 +4,6 @@ namespace app\models;
|
|||||||
use \Illuminate\Database\Eloquent\Model;
|
use \Illuminate\Database\Eloquent\Model;
|
||||||
class Post extends Model
|
class Post extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'Posts';
|
protected $table = 'post';
|
||||||
protected $fillable = ['post', 'user_id'];
|
protected $fillable = ['post', 'user_id'];
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ namespace app\models;
|
|||||||
use \Illuminate\Database\Eloquent\Model;
|
use \Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Question extends Model {
|
class Question extends Model {
|
||||||
protected $table = 'Questions';
|
protected $table = 'question';
|
||||||
protected $fillable = ['question','user_id'];
|
protected $fillable = ['question','user_id'];
|
||||||
|
|
||||||
public function answers()
|
public function answers()
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\models;
|
|
||||||
|
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Upvote extends Model {
|
|
||||||
protected $table = 'Upvotes';
|
|
||||||
protected $fillable = ['answer_id', 'user_id'];
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace app\models;
|
namespace app\models;
|
||||||
use \Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class User extends Model {
|
class User extends Model {
|
||||||
protected $table = 'user';
|
protected $table = 'user';
|
||||||
protected $fillable = ['username', 'email', 'role'];
|
protected $fillable = ['username', 'email', 'password_hash', 'role'];
|
||||||
protected $dates = ['deleted at'];
|
protected $dates = ['deleted at'];
|
||||||
}
|
}
|
||||||
|
9
app/views/questionCreate.php
Normal file
9
app/views/questionCreate.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<form action="/admin/question" method="post">
|
||||||
|
Вопрос: <br>
|
||||||
|
<label>
|
||||||
|
<textarea name = "question" rows="10" cols="50" placeholder="Введите здесь ваш вопрос"></textarea>
|
||||||
|
</label> <br> <br>
|
||||||
|
|
||||||
|
<input type = "submit" value="Подтвердить">
|
||||||
|
<input type="reset">
|
||||||
|
</form>
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Пароль:<br>
|
Пароль:<br>
|
||||||
<label>
|
<label>
|
||||||
<input type = "text" name = "password" required size="50" placeholder="Пароль">
|
<input type = "text" name = "password_hash" required size="50" placeholder="Пароль">
|
||||||
</label> <br> <br>
|
</label> <br> <br>
|
||||||
|
|
||||||
Email адрес: <br>
|
Email адрес: <br>
|
||||||
|
@ -28,6 +28,15 @@ $router->group(["prefix" => "admin"], function (RouteCollector $router){
|
|||||||
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
||||||
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
|
$router->post("/edit", [\app\controllers\UserController::class, 'actionEdit']);
|
||||||
});
|
});
|
||||||
|
$router->group(["prefix" => "question"], function (RouteCollector $router){
|
||||||
|
$router->get('/create', [QuestionController::class, 'actionCreate']);
|
||||||
|
$router->get('/update', [QuestionController::class, 'actionUpdate']);
|
||||||
|
$router->get('/delete/{id}', [QuestionController::class, 'actionDelete']);
|
||||||
|
$router->get('/', [QuestionController::class, 'actionIndex']);
|
||||||
|
$router->get('/{id}', [QuestionController::class, 'actionView']);
|
||||||
|
$router->post("/", [QuestionController::class, 'actionAdd']);
|
||||||
|
$router->post("/edit", [QuestionController::class, 'actionEdit']);
|
||||||
|
});
|
||||||
$router->group(["prefix" => "post"], function (RouteCollector $router){
|
$router->group(["prefix" => "post"], function (RouteCollector $router){
|
||||||
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
|
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
|
||||||
});
|
});
|
||||||
|
8
m.php
8
m.php
@ -1,8 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use migrations\AnswerMigration;
|
||||||
|
use migrations\PostMigration;
|
||||||
|
use migrations\QuestionMigration;
|
||||||
use migrations\UserMigration;
|
use migrations\UserMigration;
|
||||||
|
|
||||||
require_once __DIR__ . "/vendor/autoload.php";
|
require_once __DIR__ . "/vendor/autoload.php";
|
||||||
require_once __DIR__ . "/bootstrap.php";
|
require_once __DIR__ . "/bootstrap.php";
|
||||||
|
|
||||||
UserMigration::up();
|
//UserMigration::up();
|
||||||
|
//PostMigration::up();
|
||||||
|
//AnswerMigration::up();
|
||||||
|
//QuestionMigration::up();
|
37
migrations/AnswerMigration.php
Normal file
37
migrations/AnswerMigration.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
|
||||||
|
class AnswerMigration extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('answer', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('answer', 255)->nullable(false);
|
||||||
|
$table->integer('user_id');
|
||||||
|
$table->integer('question_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('user');
|
||||||
|
}
|
||||||
|
}
|
36
migrations/PostMigration.php
Normal file
36
migrations/PostMigration.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
|
||||||
|
class PostMigration extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('post', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('post', 255)->nullable(false);
|
||||||
|
$table->integer('user_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('user');
|
||||||
|
}
|
||||||
|
}
|
36
migrations/QuestionMigration.php
Normal file
36
migrations/QuestionMigration.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace migrations;
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
|
|
||||||
|
class QuestionMigration extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function up(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->create('question', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('question', 255)->nullable(false);
|
||||||
|
$table->integer('user_id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function down(): void
|
||||||
|
{
|
||||||
|
Manager::schema()->dropIfExists('user');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user