HostingSubscriptionsController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\ApiController;
  4. use App\Models\HostingSubscription;
  5. use Carbon\Carbon;
  6. use Illuminate\Http\Request;
  7. class HostingSubscriptionsController extends ApiController
  8. {
  9. public function index()
  10. {
  11. $findHostingSubscriptions = HostingSubscription::all();
  12. return response()->json([
  13. 'status' => 'ok',
  14. 'message' => 'Hosting subscriptions found',
  15. 'data' => [
  16. 'hostingSubscriptions' => $findHostingSubscriptions,
  17. ],
  18. ]);
  19. }
  20. public function store(Request $request)
  21. {
  22. $hostingSubscription = new HostingSubscription();
  23. $hostingSubscription->customer_id = $request->customer_id;
  24. $hostingSubscription->hosting_plan_id = $request->hosting_plan_id;
  25. $hostingSubscription->domain = $request->domain;
  26. // $hostingSubscription->username = $request->username;
  27. // $hostingSubscription->password = $request->password;
  28. // $hostingSubscription->description = $request->description;
  29. $hostingSubscription->setup_date = Carbon::now();
  30. $hostingSubscription->save();
  31. return response()->json([
  32. 'status' => 'ok',
  33. 'message' => 'Hosting subscription created',
  34. 'data' => [
  35. 'hostingSubscription' => $hostingSubscription,
  36. ],
  37. ]);
  38. }
  39. public function destroy($id)
  40. {
  41. $findHostingSubscription = HostingSubscription::where('id', $id)->first();
  42. if ($findHostingSubscription) {
  43. $findHostingSubscription->delete();
  44. return response()->json([
  45. 'status' => 'ok',
  46. 'message' => 'Hosting subscription deleted',
  47. ]);
  48. }
  49. return response()->json([
  50. 'status' => 'error',
  51. 'message' => 'Hosting subscription not found',
  52. ], 404);
  53. }
  54. }