Rework admin panel and other
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Services\Filament\Domain\Posts;
|
||||
use App\Dto\MainSliderDTO;
|
||||
use App\Models\MainSlider;
|
||||
use App\Models\Post;
|
||||
use App\Models\Slide;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -23,7 +24,8 @@ class PostSliderService
|
||||
public function create(): void
|
||||
{
|
||||
try {
|
||||
$this->post->mainSlider()->create([
|
||||
$post = Post::find($this->post->id);
|
||||
$slide = new Slide([
|
||||
'title' => $this->dto->title,
|
||||
'content' => $this->dto->content,
|
||||
'image' => $this->dto->image,
|
||||
@@ -33,11 +35,13 @@ class PostSliderService
|
||||
'is_active' => $this->dto->is_active,
|
||||
'start_time' => $this->dto->start_time,
|
||||
'end_time' => $this->dto->end_time,
|
||||
'slider_id' => $this->dto->slider_id,
|
||||
]);
|
||||
$post->slide()->save($slide);
|
||||
|
||||
Log::info('MainSlider created successfully', ['postTitle' => $this->post->title]);
|
||||
Log::info('Slide created successfully', ['postTitle' => $this->post->title]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to create MainSlider', [
|
||||
Log::error('Failed to create slide', [
|
||||
'postTitle' => $this->post->title,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
@@ -53,31 +57,20 @@ class PostSliderService
|
||||
public function update(): void
|
||||
{
|
||||
try {
|
||||
// Retrieve the MainSlider instance
|
||||
$mainSlider = $this->post->mainSlider;
|
||||
$post = Post::find($this->post->id);
|
||||
$post->slide()->update([
|
||||
'title' => $this->dto->title,
|
||||
'content' => $this->dto->content,
|
||||
'image' => $this->dto->image,
|
||||
'link' => $this->generatePostLink(),
|
||||
'settings' => $this->dto->settings,
|
||||
'color_theme' => $this->dto->color_theme,
|
||||
'is_active' => $this->dto->is_active,
|
||||
'start_time' => $this->dto->start_time,
|
||||
'end_time' => $this->dto->end_time,
|
||||
'slider_id' => $this->dto->slider_id,
|
||||
]);
|
||||
|
||||
|
||||
if ($mainSlider) {
|
||||
|
||||
// Update properties and save to trigger model events
|
||||
$mainSlider->fill([
|
||||
'title' => $this->dto->title,
|
||||
'content' => $this->dto->content,
|
||||
'image' => $this->dto->image,
|
||||
'link' => $this->generatePostLink(),
|
||||
'settings' => $this->dto->settings,
|
||||
'color_theme' => $this->dto->color_theme,
|
||||
'is_active' => $this->dto->is_active,
|
||||
'start_time' => $this->dto->start_time,
|
||||
'end_time' => $this->dto->end_time,
|
||||
]);
|
||||
|
||||
$mainSlider->save(); // This will trigger updating and updated observer events
|
||||
|
||||
Log::info('MainSlider updated successfully', ['postTitle' => $this->post->title]);
|
||||
} else {
|
||||
Log::warning('MainSlider not found for update', ['postTitle' => $this->post->title]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to update MainSlider', [
|
||||
'postTitle' => $this->post->title,
|
||||
|
||||
Reference in New Issue
Block a user