49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Persons;
|
|
|
|
use App\Models\Person;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class Index extends Component
|
|
{
|
|
/** Person awaiting a delete confirmation. */
|
|
public ?string $pendingDelete = null;
|
|
|
|
#[On('echo-private:presence,.PresenceChanged')]
|
|
public function onPresenceChanged(): void {}
|
|
|
|
#[On('delete-person')]
|
|
public function deletePerson(): void
|
|
{
|
|
if ($this->pendingDelete === null) {
|
|
return;
|
|
}
|
|
|
|
$person = Person::where('uuid', $this->pendingDelete)->first();
|
|
if ($person !== null) {
|
|
if ($person->avatar_path) {
|
|
Storage::disk('public')->delete($person->avatar_path);
|
|
}
|
|
$person->delete();
|
|
}
|
|
|
|
$this->pendingDelete = null;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$persons = Person::orderBy('name')->get();
|
|
|
|
return view('livewire.persons.index', [
|
|
'persons' => $persons,
|
|
'home' => $persons->where('presence', 'home')->values(),
|
|
'awayCount' => $persons->where('presence', '!=', 'home')->count(),
|
|
]);
|
|
}
|
|
}
|