Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Plant;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PlantController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function get_all_data(Request $request)
|
|
{
|
|
$expectedUser = env('API_AUTH_USER');
|
|
$expectedPw = env('API_AUTH_PW');
|
|
$header_auth = $request->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_warehouse_number' => (string) $plant->warehouse_number,
|
|
'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)
|
|
{
|
|
//
|
|
}
|
|
}
|