mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-13 07:19:40 -06:00
Livewire doesn't reload the relations when the button is clicked and the number disappears.
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* NOTICE OF LICENSE.
|
|
*
|
|
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D Community Edition
|
|
*
|
|
* @author HDVinnie <hdinnovations@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
use App\Models\Thank;
|
|
use App\Models\Torrent;
|
|
use App\Models\User;
|
|
use App\Notifications\NewThank;
|
|
use Livewire\Component;
|
|
|
|
class ThankButton extends Component
|
|
{
|
|
public ?Torrent $torrent = null;
|
|
|
|
public ?User $user = null;
|
|
|
|
final public function mount(): void
|
|
{
|
|
$this->user = auth()->user();
|
|
}
|
|
|
|
final public function store(): void
|
|
{
|
|
if ($this->user->id === $this->torrent->user_id) {
|
|
$this->dispatch('error', type: 'error', message: 'You cannot thank your own content!');
|
|
|
|
return;
|
|
}
|
|
|
|
if (Thank::query()->whereBelongsTo($this->user)->whereBelongsTo($this->torrent)->exists()) {
|
|
$this->dispatch('error', type: 'error', message: 'You have already thanked!');
|
|
|
|
return;
|
|
}
|
|
|
|
$thank = Thank::create([
|
|
'user_id' => $this->user->id,
|
|
'torrent_id' => $this->torrent->id,
|
|
]);
|
|
|
|
$uploader = $this->torrent->user;
|
|
|
|
if ($uploader->acceptsNotification($this->user, $uploader, 'torrent', 'show_torrent_thank')) {
|
|
$uploader->notify(new NewThank('torrent', $thank));
|
|
}
|
|
|
|
$this->dispatch('success', type: 'success', message: 'Your thank was successfully applied!');
|
|
|
|
$this->torrent->loadCount('thanks');
|
|
}
|
|
|
|
final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
return view('livewire.thank-button');
|
|
}
|
|
}
|