From 33d22dec5b4638371ee52867ce2c622231055c4e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 2 Jul 2025 17:26:33 +0530 Subject: [PATCH] Added plant controller file --- app/Http/Controllers/PlantController.php | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/Http/Controllers/PlantController.php diff --git a/app/Http/Controllers/PlantController.php b/app/Http/Controllers/PlantController.php new file mode 100644 index 000000000..81a845d85 --- /dev/null +++ b/app/Http/Controllers/PlantController.php @@ -0,0 +1,74 @@ +header('Authorization'); + $expectedToken = $expectedUser . ':' . $expectedPw; + + if ("Bearer " . $expectedToken !== $header_auth) + { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token' + ], 403); + } + + $plants = Plant::with('company')->orderBy('code')->get(); + $plantsData = $plants->map(function($plant) { + return [ + 'company' => $plant->company ? $plant->company->name : "", // Get company name + 'plant_code' => (String)$plant->code, + 'plant_name' => $plant->name, + 'plant_address' => $plant->address, + ]; + }); + + return response()->json([ + 'plants' => $plantsData + ]); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +}