KUJUNTI.ID MINISH3LL
Path : /var/www/html/phkaynews-v2/app/Http/Livewire/Admin/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/phkaynews-v2/app/Http/Livewire/Admin/CategoryManage.php


<?php

namespace App\Http\Livewire\Admin;

use App\Models\Category;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;
use Livewire\WithPagination;

class CategoryManage extends Component
{
    use LivewireAlert;
    use WithPagination;
    protected $paginationTheme = 'bootstrap';

    public $category, $item;
    public $s, $sortField = 'created_at', $sortDirection = 'DESC', $per_page, $readyLoadingItem = false, $trashes = false, $total_trash, $trash_all = false, $restore = false;
    public $limited = 10, $show_limit = [10, 25, 50, 100];

    protected $queryString = [
        'sortField' => ['except' => 'created_at'],
        'sortDirection' => ['except' => 'DESC'],
    ];
    protected $listeners = [
        'addCategory',
        'updateCategory',
        'confirmed',
    ];

    public function updatingS()
    {
        $this->gotoPage(1);
    }

    public function updatingLimited()
    {
        $this->gotoPage(1);
    }

    public function updatingTrashes()
    {
        $this->s = null;
        $this->gotoPage(1);
    }

    public function getCategoriesProperty()
    {
        return Category::when($this->trashes, function ($query) {
            return $query->onlyTrashed();
        })
            ->when($this->s, function ($query) {
                return $query->where(function ($query) {
                    $query->where('name', 'like', '%' . $this->s . '%');
                });
            })->orderBy($this->sortField, $this->sortDirection)->paginate($this->limited);
    }
    public function loadingItem()
    {
        $this->readyLoadingItem = true;
    }

    public function render()
    {
        $this->total_trash = Category::onlyTrashed()->count();
        $this->per_page = $this->categories->perPage();
        return view('livewire.admin.category-manage', [
            'categories' => $this->readyLoadingItem ? $this->categories : []
        ])->layout('layouts.admin');
    }

    public function sortBy($field)
    {
        if ($this->sortField === $field) {
            $this->sortDirection = $this->sortDirection === 'ASC' ? 'DESC' : 'ASC';
        } else {
            $this->sortDirection = 'ASC';
        }
        $this->sortField = $field;
    }

    public function addCategory($data)
    {
        $this->category = $data;
        $this->alert('success', 'Your item has been create successfully.', [
            'position' =>  'top',
            'toast' =>  true,
            'showCancelButton' =>  false,
            'showConfirmButton' =>  false,
            'timerProgressBar' => true,
        ]);
    }

    public function updateCategory()
    {
        $this->alert('success', 'Your item has been update successfully.', [
            'position' =>  'top',
            'toast' =>  true,
            'showCancelButton' =>  false,
            'showConfirmButton' =>  false,
            'timerProgressBar' => true,
        ]);
    }

    public function confirmed()
    {
        if ($this->trashes) {
            if ($this->restore) {
                Category::onlyTrashed()->restore();
                $this->trashes = false;
                $action = 'restore all';
            } else {
                if ($this->trash_all) {
                    Category::onlyTrashed()->forceDelete();
                    $this->trashes = false;
                    $action = "empty trashes";
                } else {
                    $this->item->forceDelete();
                    if ($this->total_trash == 1) {
                        $this->trashes = false;
                    }
                    $action = "delete";
                }
            }
        } else {
            $this->item->delete();
            $action = 'trash';
        }
        $this->alert('success', 'Your item has been ' . $action . ' successfully.', [
            'position' =>  'top',
            'toast' =>  true,
            'showCancelButton' =>  false,
            'showConfirmButton' =>  false,
            'timerProgressBar' => true,
        ]);
    }

    public function pkmRestore($id)
    {
        $category = Category::onlyTrashed()->findOrFail($id);
        $category->restore();
        if ($this->total_trash == 1) {
            $this->trashes = false;
        }
        $this->alert('success', 'Your item has been restore successfully.', [
            'position' =>  'top',
            'toast' =>  true,
            'showCancelButton' =>  false,
            'showConfirmButton' =>  false,
            'timerProgressBar' => true,
        ]);
    }

    public function restoreAll()
    {
        $this->restore = true;
        $this->confirm("You won't be able to revert this!", [
            'toast' => false,
            'position' => 'center',
            'showConfirmButton' => true,
            'onConfirmed' => 'confirmed',
            'onCancelled' => 'cancelled',
            'confirmButtonText' => 'Yes, restore it!',
            'showCancelButton' => !0,
            'cancelButtonText' => "No, cancel!",
            'customClass' => [
                'confirmButton' => 'btn btn-info mt-2',
                'cancelButton' => 'btn btn-danger ml-2 mt-2'
            ],
            'buttonsStyling' => false,
        ]);
    }

    public function emptyTrash()
    {
        $this->trash_all = !$this->trash_all;
        $this->confirm("You won't be able to revert this!", [
            'toast' => false,
            'position' => 'center',
            'showConfirmButton' => true,
            'onConfirmed' => 'confirmed',
            'onCancelled' => 'cancelled',
            'confirmButtonText' => 'Yes, empty trash!',
            'showCancelButton' => !0,
            'cancelButtonText' => "No, cancel!",
            'customClass' => [
                'confirmButton' => 'btn btn-success mt-2',
                'cancelButton' => 'btn btn-danger ml-2 mt-2'
            ],
            'buttonsStyling' => false,
        ]);
    }

    public function deleted($id)
    {
        $this->item = Category::onlyTrashed()->findOrFail($id);
        $this->confirm("You won't be able to revert this!", [
            'toast' => false,
            'position' => 'center',
            'showConfirmButton' => true,
            'onConfirmed' => 'confirmed',
            'onCancelled' => 'cancelled',
            'confirmButtonText' => 'Yes, delete it!',
            'showCancelButton' => !0,
            'cancelButtonText' => "No, cancel!",
            'customClass' => [
                'confirmButton' => 'btn btn-success mt-2',
                'cancelButton' => 'btn btn-danger ml-2 mt-2'
            ],
            'buttonsStyling' => false,
        ]);
    }

    public function destroy(Category $category)
    {
        $this->item = $category;
        $this->confirm("You won't be able to revert this!", [
            'toast' => false,
            'position' => 'center',
            'showConfirmButton' => true,
            'onConfirmed' => 'confirmed',
            'onCancelled' => 'cancelled',
            'confirmButtonText' => 'Yes, move trash!',
            'showCancelButton' => !0,
            'cancelButtonText' => "No, cancel!",
            'customClass' => [
                'confirmButton' => 'btn btn-success mt-2',
                'cancelButton' => 'btn btn-danger ml-2 mt-2'
            ],
            'buttonsStyling' => false,
        ]);
    }
}

© KUJUNTI.ID