Skip to content

Commit

Permalink
add toggle button to enable or disable
Browse files Browse the repository at this point in the history
  • Loading branch information
supundulara committed Jul 14, 2024
1 parent e3a616c commit 3bd7bde
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 10 deletions.
12 changes: 11 additions & 1 deletion app/Http/Livewire/Backend/AnnouncementTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function columns(): array
Column::make("Message", "message")
->searchable(),
Column::make("Enabled", "enabled")
->searchable(),
->sortable()
->format(function (Announcement $announcement) {
return view('backend.announcement.enabled-toggle', ['announcement' => $announcement]);
}),
Column::make("Start", "starts_at")
->sortable(),
Column::make("End", "ends_at")
Expand All @@ -42,6 +45,13 @@ public function query(): Builder
->when($this->getFilter('type'), fn ($query, $type) => $query->where('type', $type));
}

public function toggleEnable($announcementId)
{
$announcement = Announcement::findOrFail($announcementId);
$announcement->enabled = !$announcement->enabled;
$announcement->save();
}

public function filters(): array
{
$type = ["" => "Any"];
Expand Down
14 changes: 12 additions & 2 deletions app/Http/Livewire/Backend/EventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class EventsTable extends DataTableComponent
{
public array $perPageAccepted = [25, 50, 100];
public array $perPageAccepted = [4, 10, 100];
public bool $perPageAll = true;


Expand All @@ -25,7 +25,10 @@ public function columns(): array
->searchable(),
Column::make('Link Caption'),
Column::make("Enabled", "enabled")
->searchable(),
->sortable()
->format(function (Event $event) {
return view('backend.event.enabled-toggle', ['event' => $event]);
}),
Column::make("Start Time", "start_at")
->searchable(),
Column::make("End Time", "end_at")
Expand All @@ -47,6 +50,13 @@ public function query(): Builder
->when($this->getFilter('type'), fn ($query, $type) => $query->where('type', $type));
}

public function toggleEnable($eventId)
{
$event = Event::findOrFail($eventId);
$event->enabled = !$event->enabled;
$event->save();
}

// public function filters(): array
// {
// $type = ["" => "Any"];
Expand Down
12 changes: 11 additions & 1 deletion app/Http/Livewire/Backend/NewsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public function columns(): array
->searchable(),
Column::make('Link Caption'),
Column::make("Enabled", "enabled")
->searchable(),
->sortable()
->format(function (News $news) {
return view('backend.news.enabled-toggle', ['news' => $news]);
}),
Column::make("Created At", "created_at")
->sortable(),
Column::make("Updated At", "updated_at")
Expand All @@ -41,6 +44,13 @@ public function query(): Builder
->when($this->getFilter('type'), fn ($query, $type) => $query->where('type', $type));
}

public function toggleEnable($newsId)
{
$news = News::findOrFail($newsId);
$news->enabled = !$news->enabled;
$news->save();
}

// public function filters(): array
// {
// $type = ["" => "Any"];
Expand Down
7 changes: 7 additions & 0 deletions resources/views/backend/announcements/enabled_toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@if($announcement->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;"
wire:click="toggleEnable({{ $announcement->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;"
wire:click="toggleEnable({{ $announcement->id }})"></i>
@endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

<x-livewire-tables::table.cell>
@if($row->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678;"></i>
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64;"></i>
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@endif
</x-livewire-tables::table.cell>

Expand Down
7 changes: 7 additions & 0 deletions resources/views/backend/event/enabled_toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@if($event->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;"
wire:click="toggleEnable({{ $event->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;"
wire:click="toggleEnable({{ $event->id }})"></i>
@endif
5 changes: 3 additions & 2 deletions resources/views/backend/event/index-table-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@

<x-livewire-tables::table.cell>
@if($row->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678;"></i>
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64;"></i>
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@endif
</x-livewire-tables::table.cell>




<x-livewire-tables::table.cell>
<div class="custom-width-1" style="width: 75px;">
{{ $row->start_at }}
Expand Down
7 changes: 7 additions & 0 deletions resources/views/backend/news/enabled_toggle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@if($news->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;"
wire:click="toggleEnable({{ $news->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;"
wire:click="toggleEnable({{ $news->id }})"></i>
@endif
4 changes: 2 additions & 2 deletions resources/views/backend/news/index-table-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

<x-livewire-tables::table.cell>
@if($row->enabled)
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678;"></i>
<i class="fas fa-toggle-on fa-2x" style="color: #0ca678; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@else
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64;"></i>
<i class="fas fa-toggle-on fa-2x fa-rotate-180" style="color: #3c4b64; cursor: pointer;" wire:click="toggleEnable({{ $row->id }})"></i>
@endif
</x-livewire-tables::table.cell>

Expand Down
1 change: 1 addition & 0 deletions routes/backend/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
->push(__('Edit'));
});


// Update
Route::put('event/{event}', [EventController::class, 'update'])
->name('event.update');
Expand Down

0 comments on commit 3bd7bde

Please sign in to comment.