add all controllers logic
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Messaging;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class MessageCollection extends ResourceCollection
|
||||
{
|
||||
public function with($request): array
|
||||
{
|
||||
if (!method_exists($this->resource, 'total')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'meta' => [
|
||||
'total' => $this->resource->total() ?? null,
|
||||
'per_page' => $this->resource->perPage() ?? null,
|
||||
'current_page' => $this->resource->currentPage() ?? null,
|
||||
'last_page' => $this->resource->lastPage() ?? null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
return $this->collection->map(function ($item) use ($request) {
|
||||
return (new MessageResource($item))->toArray($request);
|
||||
})->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Messaging;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MessageResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id ?? null,
|
||||
'sender_id' => $this->sender_id ?? null,
|
||||
'recipient_id' => $this->recipient_id ?? null,
|
||||
'subject' => $this->subject ?? null,
|
||||
'message' => $this->message ?? null,
|
||||
'sent_datetime' => optional($this->sent_datetime)->toDateTimeString(),
|
||||
'read_status' => (bool) ($this->read_status ?? false),
|
||||
'read_datetime' => optional($this->read_datetime)->toDateTimeString(),
|
||||
'message_number' => $this->message_number ?? null,
|
||||
'priority' => $this->priority ?? null,
|
||||
'attachment' => $this->attachment ?? null,
|
||||
'status' => $this->status ?? null,
|
||||
'semester' => $this->semester ?? null,
|
||||
'school_year' => $this->school_year ?? null,
|
||||
'sender_name' => $this->sender ? trim($this->sender->firstname . ' ' . $this->sender->lastname) : null,
|
||||
'recipient_name' => $this->recipient ? trim($this->recipient->firstname . ' ' . $this->recipient->lastname) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Messaging;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RecipientResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->resource['id'] ?? null,
|
||||
'name' => $this->resource['name'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user