blog api created
This commit is contained in:
1 parent
4f101885a8
commit
d98bc7bbb0
27 files changed
+1022
-44
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CategoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'description' => $this->description,
|
||||
'short_description' => $this->short_description,
|
||||
'image' => $this->image,
|
||||
'posts_count' => $this->whenLoaded('posts', function () {
|
||||
return $this->posts->count();
|
||||
}),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('M d Y'),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('M d Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PostResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'slug' => $this->slug,
|
||||
'excerpt' => $this->excerpt,
|
||||
'body' => $this->body,
|
||||
'author' => new UserResource($this->author),
|
||||
'category' => new CategoryResource($this->category),
|
||||
'tags' => TagResource::collection($this->tags),
|
||||
'featured_image' => $this->featured_image,
|
||||
'views' => $this->views,
|
||||
'likes' => $this->likes,
|
||||
'published_at' => $this->published_at,
|
||||
'created_at' => Carbon::parse($this->created_at)->format('M d Y'),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('M d Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TagResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'posts_count' => $this->whenLoaded('posts', function () {
|
||||
return $this->posts->count();
|
||||
}),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('M d Y'),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('M d Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,12 @@ class User extends ResourceCollection
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
// اضافه کردن سایر فیلدهای مورد نیاز
|
||||
'email' => $this->email,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -18,8 +19,8 @@ class UserResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'created_at' => Carbon::parse($this->created_at)->format('M d Y'),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('M d Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user