-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2831ce
commit ae29f10
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Resources\OrganizationResource; | ||
use App\Models\Organisation; | ||
|
||
class OrganizationController extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
return OrganizationResource::collection( | ||
Organisation::query() | ||
->with('riskCategories') | ||
->with('activityCounties') | ||
->with('expertises') | ||
->with('resourceTypes') | ||
->with('volunteers') | ||
->get() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Resources\ResourceResource; | ||
use App\Models\Resource; | ||
|
||
class ResourceController extends Controller | ||
{ | ||
public function __invoke() | ||
{ | ||
return ResourceResource::collection( | ||
Resource::query() | ||
->with('county') | ||
->with('organisation') | ||
->with('category') | ||
->with('subcategory') | ||
->with('types') | ||
->get() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class IdAndNameResource 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 | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class OrganizationResource 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, | ||
'type' => $this->type, | ||
'status' => $this->status, | ||
'expertises_area' => IdAndNameResource::collection($this->expertises), | ||
'risc_category' => IdAndNameResource::collection($this->riskCategories), | ||
'action_type' => IdAndNameResource::collection($this->resourceTypes), | ||
'activity_area' => $this->area, | ||
'county' => IdAndNameResource::collection($this->activityCounties), | ||
'created_at' => $this->created_at->format("Y-m-d H:i:s"), | ||
'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), | ||
'volunteers_count' => $this->volunteers->count(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ResourceResource 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, | ||
'county' => IdAndNameResource::make($this->county), | ||
'organization' => IdAndNameResource::make($this->organisation), | ||
'category' => IdAndNameResource::make($this->category), | ||
'subcategory' => IdAndNameResource::make($this->subcategory), | ||
// 'types' => IdAndNameResource::collection($this->types), | ||
'created_at' => $this->created_at->format("Y-m-d H:i:s"), | ||
'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), | ||
]; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters