Skip to content

Commit 4a41e6e

Browse files
committed
fix: update slug for resources
1 parent bd2283b commit 4a41e6e

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

src/Http/Resources/CategoryResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CSlant\Blog\Api\Http\Resources;
44

55
use CSlant\Blog\Core\Models\Category;
6+
use CSlant\Blog\Core\Models\Slug;
67
use Illuminate\Http\Resources\Json\JsonResource;
78

89
/**
@@ -20,7 +21,7 @@ public function toArray($request): array
2021
return [
2122
'id' => $this->id,
2223
'name' => $this->name,
23-
'slug' => $this->slug,
24+
'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
2425
'url' => $this->url,
2526
'icon' => $this->icon,
2627
'description' => $this->description,

src/Http/Resources/ListCategoryResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CSlant\Blog\Core\Facades\Base\BaseHelper;
66
use CSlant\Blog\Core\Http\Resources\Base\BaseListCategoryResource;
77
use CSlant\Blog\Core\Models\Category;
8+
use CSlant\Blog\Core\Models\Slug;
89
use Illuminate\Http\Request;
910

1011
/**
@@ -22,7 +23,7 @@ public function toArray($request): array
2223
return [
2324
'id' => $this->id,
2425
'name' => $this->name,
25-
'slug' => $this->slug->key,
26+
'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
2627
'icon' => $this->icon ? BaseHelper::renderIcon($this->icon) : null,
2728
'description' => $this->description,
2829
'children' => CategoryResource::collection($this->children),

src/Http/Resources/ListPostResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
66
use CSlant\Blog\Core\Http\Resources\Base\BaseListPostResource;
77
use CSlant\Blog\Core\Models\Post;
8+
use CSlant\Blog\Core\Models\Slug;
89
use Illuminate\Http\Request;
910

1011
/**
@@ -22,7 +23,7 @@ public function toArray($request): array
2223
return [
2324
'id' => $this->id,
2425
'name' => $this->name,
25-
'slug' => $this->slug,
26+
'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
2627
'description' => $this->description,
2728
'image' => $this->image ? RvMedia::url($this->image) : null,
2829
'categories' => CategoryResource::collection($this->categories),

src/Http/Resources/PostResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CSlant\Blog\Core\Facades\Base\Media\RvMedia;
66
use CSlant\Blog\Core\Models\Post;
7+
use CSlant\Blog\Core\Models\Slug;
78
use Illuminate\Http\Resources\Json\JsonResource;
89

910
/**
@@ -21,7 +22,7 @@ public function toArray($request): array
2122
return [
2223
'id' => $this->id,
2324
'name' => $this->name,
24-
'slug' => $this->slug->key,
25+
'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
2526
'description' => $this->description,
2627
'content' => $this->content,
2728
'image' => $this->image ? RvMedia::url($this->image) : null,

src/Http/Resources/TagResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CSlant\Blog\Api\Http\Resources;
44

5+
use CSlant\Blog\Core\Models\Slug;
56
use CSlant\Blog\Core\Models\Tag;
67
use Illuminate\Http\Resources\Json\JsonResource;
78

@@ -21,7 +22,7 @@ public function toArray($request): array
2122
return [
2223
'id' => $this->id,
2324
'name' => $this->name,
24-
'slug' => $this->slug->key,
25+
'slug' => $this->slug instanceof Slug ? $this->slug->key : $this->slug,
2526
'description' => $this->description,
2627
];
2728
}

0 commit comments

Comments
 (0)