forked from UnlockedLabs/UnlockEdv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ProviderPlaform CRUD UN-183
- Loading branch information
1 parent
d390a4b
commit e6a8318
Showing
1 changed file
with
96 additions
and
0 deletions.
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,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(); | ||
} | ||
} |