| Path : /proc/self/root/var/www/html/phkaynews-v2/app/Http/Livewire/Admin/Partcials/ |
|
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
| Current File : //proc/self/root/var/www/html/phkaynews-v2/app/Http/Livewire/Admin/Partcials/AdvertiseForm.php |
<?php
namespace App\Http\Livewire\Admin\Partcials;
use App\Models\Advertise;
use Livewire\Component;
use Livewire\WithFileUploads;
class AdvertiseForm extends Component
{
use WithFileUploads;
public $modal_id, $advertise, $feature_image;
public $no_image = 'backend/images/no-thumbnail.jpg', $old_image, $update_image, $type_key;
public function mount($modalId, $advertise = null)
{
$this->modal_id = $modalId;
$this->advertise = $advertise;
if (!empty($advertise)) {
$this->old_image = $advertise->feature_image;
$this->type_key = $advertise->type;
}
}
protected $rules = [
'advertise.name' => 'required',
'advertise.url' => 'required|url',
'advertise.order' => 'required',
'advertise.type' => 'required',
'feature_image' => 'image|max:1024'
];
public function dehydrate()
{
if (empty($this->advertise)) {
$this->advertise['type'] = 'hp';
}
}
public function updatedAdvertisetype()
{
$this->type_key = $this->advertise['type'];
}
public function render()
{
return view('livewire.admin.partcials.advertise-form');
}
public function submit()
{
if (isset($this->advertise->id)) {
if (!empty($this->update_image)) {
$this->validate([
'update_image' => 'image|max:1024'
]);
$old_img_path = public_path($this->old_image); //is get path old image
if (file_exists($old_img_path)) {
unlink($old_img_path);
}
$this->old_image = '';
$updated_image = $this->update_image->store('ads');
}
$this->advertise->update([
'name' => $this->advertise['name'],
'url' => $this->advertise['url'],
'order' => $this->advertise['order'],
'type' => $this->advertise['type'],
'feature_image' => empty($this->old_image) ? $updated_image : $this->old_image
]);
$this->emit('updateAdvertise');
} else {
$this->validate();
$file = $this->feature_image->store('ads');
Advertise::create([
'name' => $this->advertise['name'],
'url' => $this->advertise['url'],
'order' => $this->advertise['order'],
'type' => $this->advertise['type'],
'feature_image' => $file
]);
$this->emit('addAdvertise', $this->advertise);
$this->advertise = null;
$this->resetValidation();
}
$this->dispatchBrowserEvent('closeModal', ['modalId' => $this->modal_id]);
}
}