Skip to content

Commit

Permalink
Add option to archive tags
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderglueck committed Aug 19, 2023
1 parent d1342e1 commit e7e1442
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/DayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function create(Request $request): View
return view('day.create', [
'day' => new Day(['date' => $validated['initial'] ?? date('Y-m-d')]),
'categories' => Category::orderBy('order')->get(),
'tags' => $request->user()->tags
'tags' => $request->user()->tags()->whereNull('archived_at')->get()
]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function edit(Tag $tag): View
public function update(TagEditRequest $request, Tag $tag): RedirectResponse
{
$tag->fill($request->validated());
$tag->archived_at = $request->has('archive') ? now() : null;
$tag->save();

return redirect()->route('tags.index');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/TagEditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function rules(): array
{
return [
'name' => ['required'],
'color' => ['required', 'size:7', 'starts_with:#']
'color' => ['required', 'size:7', 'starts_with:#'],
'archive' => ['sometimes', 'required', 'boolean']
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('tags', function (Blueprint $table) {
$table->timestamp('archived_at')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('tags', function (Blueprint $table) {
$table->dropColumn('archived_at');
});
}
};
9 changes: 9 additions & 0 deletions resources/views/tag/widgets/edit_tag.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

@include('tag.partials.edit')

<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="archive" id="flexCheckDefault" @checked(old('archived', $tag->archived_at != null))>
<label class="form-check-label" for="flexCheckDefault">
Archive
</label>
</div>
</div>

<button type="submit" class="btn btn-primary">
Edit
</button>
Expand Down

0 comments on commit e7e1442

Please sign in to comment.