Path : /var/www/html/phkaynews-v2/app/Http/Livewire/Admin/ |
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/AdvertiseManage.php |
<?php namespace App\Http\Livewire\Admin; use Livewire\Component; use App\Models\Advertise; use Jantinnerezo\LivewireAlert\LivewireAlert; use Livewire\WithPagination; class AdvertiseManage extends Component { use WithPagination; use LivewireAlert; protected $paginationTheme = 'bootstrap'; public $item, $total_ads; 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 $listeners = [ 'addAdvertise', 'updateAdvertise', 'confirmed', ]; public function updatingTrashes() { $this->gotoPage(1); } public function getAdvertisesProperty() { return Advertise::when($this->trashes, function ($query) { return $query->onlyTrashed(); })->when($this->s, function ($query) { return $query->where('name', 'like', '%' . $this->s . '%'); })->orderBy('id', 'desc')->paginate($this->limited); } public function render() { if ($this->trashes) { $this->total_ads = Advertise::onlyTrashed()->count(); } else { $this->total_ads = Advertise::count(); } $this->total_trash = Advertise::onlyTrashed()->count(); $this->per_page = $this->advertises->perPage(); return view('livewire.admin.advertise-manage', [ 'advertises' => $this->readyLoadingItem ? $this->advertises : [] ])->layout('layouts.admin'); } public function loadingItem() { $this->readyLoadingItem = true; } public function addAdvertise($data) { $this->advertise = $data; $this->alert('success', 'Your item has been create successfully.', [ 'position' => 'top', 'toast' => true, 'showCancelButton' => false, 'showConfirmButton' => false, 'timerProgressBar' => true, ]); } public function updateAdvertise() { $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) { Advertise::onlyTrashed()->restore(); $this->trashes = false; $action = 'restore all'; } else { if ($this->trash_all) { $ad_images=Advertise::onlyTrashed()->get()->pluck('feature_image'); foreach ($ad_images as $image) { $d_image = public_path($image); if (file_exists($d_image)) { unlink($d_image); } } Advertise::onlyTrashed()->forceDelete(); $this->trashes = false; $action = "empty trashes"; } else { $this->item->forceDelete(); $old_img = public_path($this->item->feature_image); //is get path old image if (file_exists($old_img)) { unlink($old_img); } 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 = Advertise::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 = Advertise::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(Advertise $advertise) { $this->item = $advertise; $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, ]); } }