diff --git a/app/Http/Controllers/QuestionsController.php b/app/Http/Controllers/QuestionsController.php index 65c385b914bd0fac8690eb05b663494b6f12a2cc..081f17496448b8b474fda2f5e451e98150c07f6c 100644 --- a/app/Http/Controllers/QuestionsController.php +++ b/app/Http/Controllers/QuestionsController.php @@ -77,11 +77,17 @@ class QuestionsController extends Controller 'topic' => 'required', 'body' => 'required' ]); + + $is_anon = 0; + if ($request->input('anon') === 'yes') { + $is_anon = '1'; + } //Add Question $question = new Question; $question->topic = $request->input('topic'); $question->body = $request->input('body'); + $question->is_anon = $is_anon; if ($isAdmin) { $question->user_id = Auth::user()->id; $question->is_admin = 1; @@ -182,12 +188,18 @@ class QuestionsController extends Controller 'body' => 'required' ]); + $is_anon = 0; + if ($request->input('anon') === 'yes') { + $is_anon = '1'; + } + $question = Question::find($id); $member = Auth::guard('member')->user(); if ($isAdmin || ($question->user()->id == $member->id && $question->is_admin == 0)) { $question->topic = $request->input('topic'); $question->body = $request->input('body'); + $question->is_anon = $is_anon; $question->save(); if ($isAdmin) { return redirect('/admin/questions/' . $id)->with('success', 'Question Updated'); diff --git a/database/migrations/2018_04_23_172156_add_is_anon_to_questions_table.php b/database/migrations/2018_04_23_172156_add_is_anon_to_questions_table.php new file mode 100644 index 0000000000000000000000000000000000000000..f8fd499394e49ebaab5e41ef5602b27f46e51250 --- /dev/null +++ b/database/migrations/2018_04_23_172156_add_is_anon_to_questions_table.php @@ -0,0 +1,32 @@ +<?php + +use Illuminate\Support\Facades\Schema; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +class AddIsAnonToQuestionsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('questions', function($table) { + $table->tinyInteger('is_anon')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('questions', function($table){ + $table->dropColumn('is_anon'); + }); + } +} diff --git a/resources/views/admin/addquestion.blade.php b/resources/views/admin/addquestion.blade.php index cc83207cda2b2123f56bbfe9a177d05ee0e6d9a6..8b7847af914ba1723adaa3289433ec5e0038a610 100644 --- a/resources/views/admin/addquestion.blade.php +++ b/resources/views/admin/addquestion.blade.php @@ -13,7 +13,16 @@ {{Form::label('topic', 'Topic')}} {{Form::text('topic', '', ['class' => 'form-control', 'placeholder' => 'Topic'])}} </div> - <div class="form-group"> + <div class="form-group" style="width:30%;"> + <div style="float:left;">{{Form::label('anon', 'Anonymous')}} </div> + <div class="pull-right"> + <label class="switch"> + <input name="anon" id="anon" value="yes" type="checkbox"> + <span class="slider round"></span> + </label> + </div> + </div> + <div class="form-group" style="clear:both;"> {{Form::label('body', 'Question')}} {{Form::textarea('body', '', ['class' => 'form-control', 'placeholder' => 'Question'])}} </div> diff --git a/resources/views/admin/editquestion.blade.php b/resources/views/admin/editquestion.blade.php index 299aa0e9376865c767c8778eb112816dadf632d0..4e2df557ed5216d496c4eb4981d91fc17cadf617 100644 --- a/resources/views/admin/editquestion.blade.php +++ b/resources/views/admin/editquestion.blade.php @@ -13,7 +13,20 @@ {{Form::label('topic', 'Topic')}} {{Form::text('topic', $question->topic, ['class' => 'form-control', 'placeholder' => 'Topic'])}} </div> - <div class="form-group"> + <div class="form-group" style="width:30%;"> + <div style="float:left;">{{Form::label('anon', 'Anonymous')}} </div> + <div class="pull-right"> + <label class="switch"> + @if ($question->is_anon == 1) + <input name="anon" id="anon" value="yes" type="checkbox" checked> + @else + <input name="anon" id="anon" value="yes" type="checkbox"> + @endif + <span class="slider round"></span> + </label> + </div> + </div> + <div class="form-group" style="clear:both;"> {{Form::label('body', 'Question')}} {{Form::textarea('body', $question->body, ['class' => 'form-control', 'placeholder' => 'Question'])}} </div> diff --git a/resources/views/admin/showeachquestion.blade.php b/resources/views/admin/showeachquestion.blade.php index 1907467bb693513d28d14ecdbd167ee6541a66ce..a69f3f639427669685aa9ded050f4a3a79889519 100644 --- a/resources/views/admin/showeachquestion.blade.php +++ b/resources/views/admin/showeachquestion.blade.php @@ -18,6 +18,9 @@ @else <small class="text-footer">by {{$question->member->name}}</small> @endif + @if ($question->is_anon == 1) + (anon) + @endif <hr> </div> @if((!Auth::guest() && Auth::user()->IsAdmin == 1) || (Auth::guard('member')->user() != null && $question->member->id == Auth::guard('member')->user()->id && $question->is_admin == 0)) diff --git a/resources/views/admin/showquestion.blade.php b/resources/views/admin/showquestion.blade.php index 8959ca3fc08950d0692b50ddb60920ef9dd830ff..cae19d664587658c65c1e3c053ae1b89acef75d5 100644 --- a/resources/views/admin/showquestion.blade.php +++ b/resources/views/admin/showquestion.blade.php @@ -24,9 +24,12 @@ <small class="text-footer"> <i> @if ($question->is_admin == 1) - Written on {{$question->created_at->format('d M Y')}} by {{$question->user->name}} as <span style="color:blue;">admin</span> + Written on {{$question->created_at->format('d M Y')}}<br>by {{$question->user->name}} as <span style="color:blue;">admin</span> @else - Written on {{$question->created_at->format('d M Y')}} by {{$question->member->name}} + Written on {{$question->created_at->format('d M Y')}}<br>by {{$question->member->name}} + @endif + @if ($question->is_anon == 1) + (anon) @endif </i> </small>