Skip to content
Snippets Groups Projects
Commit 4e8c9187 authored by Thoeni Fabian (Student Com20)'s avatar Thoeni Fabian (Student Com20)
Browse files

v2

parent 3a6b3c47
No related branches found
No related tags found
No related merge requests found
......@@ -4,32 +4,38 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ListQuestion;
use App\Models\Answers;
class QuestionController extends Controller
{
public function index(){
return view('home', ['Questions' => ListQuestion::all()]);
return view('home', ['Questions' => ListQuestion::all()], ['Answerss' => Answers::all()],);
}
public function saveQuestion(Request $request){
$newListQuestion = new ListQuestion;
$newListQuestion->question = $request->ListQuestion;
$newListQuestion->user = auth()->user()->name;
//$newListQuestion->answer = $request->ListQuestion;
$newListQuestion->save();
//\Log::info(json_encode($request->all()));
//return redirect('/', ['Questions' => ListQuestion::all()]);
return back();
return redirect('/');
//return view('home', ['Questions' => ListQuestion::all()]);
}
public function saveAnswer(Request $request){
$newListQuestion = new ListQuestion;
$newListQuestion->question = $request->ListQuestion;
$newListQuestion->save();
$newAnswer = new Answers;
$newAnswer->questionId = $request->currentId;
$newAnswer->answers = $request->Answers;
$newAnswer->user = auth()->user()->name;
$newAnswer->save();
//\Log::info(json_encode($request->all()));
return redirect('/');
return redirect('/');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MeinModel extends Model
{
public $timestamps = false;
use HasFactory;
}
......@@ -16,7 +16,7 @@ class CreateListQuestionsTable extends Migration
Schema::create('list_questions', function (Blueprint $table) {
$table->id();
$table->string('question');
$table->string('answer');
$table->string('user');
$table->timestamps();
});
}
......
......@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMeinModelsTable extends Migration
class CreateAnswersTable extends Migration
{
/**
* Run the migrations.
......@@ -13,9 +13,12 @@ class CreateMeinModelsTable extends Migration
*/
public function up()
{
Schema::create('mein_models', function (Blueprint $table) {
Schema::create('answers', function (Blueprint $table) {
$table->id();
$table->string('question');
$table->integer('questionId');
$table->string('answers');
$table->string('user');
$table->timestamps();
});
}
......@@ -26,6 +29,6 @@ class CreateMeinModelsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('mein_models');
Schema::dropIfExists('answers');
}
}
......@@ -3,12 +3,12 @@
@import url('https://fonts.googleapis.com/css?family=Numans');
html,body{
background-image: url('https://wallpaperaccess.com/full/187161.jpg');
background-image: url('https://steamcdn-a.akamaihd.net/steamcommunity/public/images/items/286300/c33a58cd147d270171996c766b102de411603d89.jpg'); /*('https://wallpaperaccess.com/full/187161.jpg');*/
background-repeat: repeat-y;
background-size: cover;
height: 100%;
font-family: 'Numans', sans-serif;
}
.top-buffer { margin-top:15px;}
......@@ -33,7 +33,9 @@
@foreach ($Questions as $ListQuestion)
<div class="card">
<div class="card-header">{{ __('Question:') }} {{ $ListQuestion->question}}</div>
<div class="card-header">{{ __('Question:') }} {{ $ListQuestion->question}}
<div>Question by: {{ $ListQuestion->user}}</div>
</div>
<div class="card-body">
@if (session('status'))
......@@ -42,11 +44,18 @@
</div>
@endif
<form method="post" action="{{ route('saveQuestionRoute') }}">
<form method="post" action="{{ route('saveAnswerRoute') }}">
{{ csrf_field() }}
@foreach ($Answerss as $Answers)
@if($ListQuestion->id == $Answers->questionId)
<p>{{ $Answers->user}}: {{ $Answers->answers}} </p>
@endif
@endforeach
<input type="hidden" name="currentId" value="{{ $ListQuestion->id}}" />
<div class="form-group">
<input type="text" name="Answer" class="form-control" placeholder="Enter answer">
<button type="submit" class="top-buffer">Submit Answer</button>
<input type="text" name="Answers" class="form-control" placeholder="Enter answer">
<button type="submit" class="top-buffer">Submit Answer</button>
</div>
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment