Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbrandB authored and github-actions[bot] committed Jun 18, 2024
1 parent 744e4d7 commit 6ad9d90
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\Item;
use App\Models\Question;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Inertia\Inertia;
use Vinkla\Hashids\Facades\Hashids;
Expand Down
13 changes: 7 additions & 6 deletions app/Http/Controllers/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Models\Answer;
use App\Models\AttributeType;
use App\Models\Question;
use Illuminate\Http\Request;
Expand All @@ -14,15 +13,15 @@ class QuestionController extends Controller
public function index()
{
return Inertia::render('Questions/Index', [
'questions' => Question::all()
'questions' => Question::all(),
]);
}

public function create()
{
return Inertia::render('Questions/Edit', [
'question' => null,
'attributeTypes' => AttributeType::with('attributes:id,title,attribute_type_id', 'attributes.attributeType:id,color')->get()
'attributeTypes' => AttributeType::with('attributes:id,title,attribute_type_id', 'attributes.attributeType:id,color')->get(),
]);
}

Expand All @@ -34,7 +33,7 @@ public function edit($id)
{
return Inertia::render('Questions/Edit', [
'question' => Question::with('answers', 'answers.attributes:id,title,attribute_type_id', 'answers.attributes.attributeType:id,color')->findOrFail($id),
'attributeTypes' => AttributeType::with('attributes:id,title,attribute_type_id', 'attributes.attributeType:id,color')->get()
'attributeTypes' => AttributeType::with('attributes:id,title,attribute_type_id', 'attributes.attributeType:id,color')->get(),
]);
}

Expand All @@ -43,19 +42,21 @@ public function update(Request $request, $id)
$question = Question::findOrFail($id);
$question->update($request->only('text', 'description'));
foreach ($request->input('answers') as $newAnswer) {
$answer = $question->answers()->updateOrCreate(['id' => $newAnswer['id']??null], ['text' => $newAnswer['text']]);
$answer = $question->answers()->updateOrCreate(['id' => $newAnswer['id'] ?? null], ['text' => $newAnswer['text']]);
$answer->attributes()->sync(collect($newAnswer['attributes'])->pluck('id'));
}

return to_route('questions.edit', $question->id)->with('success', 'Question saved!');
}

public function destroy($id)
{
DB::transaction(function () use ($id) {
DB::transaction(static function () use ($id): void {
$question = Question::findOrFail($id);
$question->answers()->delete();
$question->delete();
});

return redirect()->route('questions.index')->with('success', 'Question deleted!');
}
}
2 changes: 2 additions & 0 deletions app/Models/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class Answer extends Model
{
use HasFactory;

protected $hidden = ['created_at', 'updated_at'];

protected $fillable = [
'text',
];
Expand Down
1 change: 0 additions & 1 deletion app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ public function answers(): HasMany
{
return $this->hasMany(Answer::class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
return new class extends Migration
{
public function up(): void
{
Schema::create('questions', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
return new class extends Migration
{
public function up(): void
{
Schema::create('answers', function (Blueprint $table) {
Expand Down

0 comments on commit 6ad9d90

Please sign in to comment.