Skip to content

Commit

Permalink
feat: add ProviderPlaform CRUD UN-183
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissantillan committed Dec 13, 2023
1 parent d390a4b commit e6a8318
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions app/Http/Controllers/v1/ProviderPlatformController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App\Http\Controllers\v1;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreProviderPlatformRequest;
use App\Http\Requests\UpdateProviderPlatformRequest;
use App\Http\Resources\PaginateResource;
use App\Http\Resources\ProviderPlatformResource;
use App\Models\ProviderPlatform;

class ProviderPlatformController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$providerPlatforms = ProviderPlatform::paginate(10);

return PaginateResource::make($providerPlatforms, ProviderPlatformResource::class);
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreProviderPlatformRequest $request)
{
try {
$providerPlatform = $request->validated();
} catch (\Throwable $th) {
return response()->json([
'message' => 'Request Validation failed.',
'errors' => $th->getMessage(),
], 422);
}
$newProviderPlatform = ProviderPlatform::create($providerPlatform);
$newProviderPlatform->hashAccessKey();

return ProviderPlatformResource::make($newProviderPlatform);
}

/**
* Display the specified resource.
*/
public function show(ProviderPlatform $providerPlatform)
{
return ProviderPlatformResource::make($providerPlatform);
}

/**
* Show the form for editing the specified resource.
*/
public function edit(ProviderPlatform $providerPlatform)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateProviderPlatformRequest $request, ProviderPlatform $providerPlatform)
{
try {
$validated = $request->validated();
} catch (\Throwable $th) {
return response()->json([
'message' => 'Request Validation failed.',
'errors' => $th->getMessage(),
], 422);
}
$providerPlatform = ProviderPlatform::findOrFail($providerPlatform->id);
$providerPlatform->update($validated);

return ProviderPlatformResource::make($providerPlatform);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(ProviderPlatform $providerPlatform)
{
$providerPlatform = ProviderPlatform::findOrFail($providerPlatform->id);
$providerPlatform->delete();

return response()->noContent();
}
}

0 comments on commit e6a8318

Please sign in to comment.