Skip to content

Commit

Permalink
service provider updated
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Feb 14, 2024
1 parent b950f8c commit 77f9c20
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Http/Controllers/AssignVendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AssignVendorController extends Controller
/**
* Store a newly created resource in storage.
*/
public function available(string $id)
public function available(string $id): \Illuminate\Http\JsonResponse|\Fintech\Remit\Http\Resources\AssignableVendorCollection
{
try {

Expand All @@ -28,9 +28,11 @@ public function available(string $id)

$serviceVendors = \Fintech\Business\Facades\Business::serviceVendor()->list([
'service_id_array' => [$order->service_id],
'enabled' => true,
'paginate' => false,
]);
dd($serviceVendors);

return new \Fintech\Remit\Http\Resources\AssignableVendorCollection($serviceVendors);

} catch (ModelNotFoundException $exception) {

Expand Down
48 changes: 48 additions & 0 deletions src/Http/Resources/AssignableVendorCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Fintech\Remit\Http\Resources;

use Fintech\Core\Supports\Constant;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class AssignableVendorCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param Request $request
* @return array
*/
public function toArray($request)
{
return $this->collection->map(function ($vendor) {
return [
'id' => $vendor->getKey() ?? null,
'service_vendor_name' => $vendor->service_vendor_name ?? null,
'service_vendor_slug' => $vendor->service_vendor_slug ?? null,
'service_vendor_data' => $vendor->service_vendor_data ?? null,
'service_vendor_logo_svg' => $vendor->getFirstMediaUrl('logo_svg') ?? null,
'service_vendor_logo_png' => $vendor->getFirstMediaUrl('logo_png') ?? null,
'enabled' => $vendor->enabled ?? null,
];
})->toArray();
}

/**
* Get additional data that should be returned with the resource array.
*
* @return array<string, mixed>
*/
public function with(Request $request): array
{
return [
'options' => [
'dir' => Constant::SORT_DIRECTIONS,
'per_page' => Constant::PAGINATE_LENGTHS,
'sort' => ['id', 'name', 'created_at', 'updated_at'],
],
'query' => $request->all(),
];
}
}

0 comments on commit 77f9c20

Please sign in to comment.