Add plant code retrieval in user controller to enhance user data response
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Hash;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -61,6 +62,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
$existUser = User::where('name', $header_user)->first();
|
||||
$existPlant = "All Plants";
|
||||
|
||||
if (!$existUser)
|
||||
{
|
||||
@@ -69,13 +71,13 @@ class UserController extends Controller
|
||||
'status_description' => 'Unknown user name found!'
|
||||
], 400);
|
||||
}
|
||||
// if ($header_user != $existUser->name)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => 'Unknown user name found'
|
||||
// ], 400);
|
||||
// }
|
||||
else {
|
||||
$codeExist = Plant::where('id', $existUser->plant_id)->first();
|
||||
if ($codeExist) {
|
||||
$existPlant = $codeExist->code;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Retrieve the user by email
|
||||
//$user = User::where('email', $email)->first();
|
||||
@@ -83,6 +85,7 @@ class UserController extends Controller
|
||||
return response()->json([
|
||||
'created_at' => $existUser->created_at->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $existUser->updated_at->format('Y-m-d H:i:s'),
|
||||
'plant' => (String)$existPlant,
|
||||
'email' => $existUser->email,
|
||||
'roles' => $existUser->roles()->pluck('name')->toArray()
|
||||
], 200);
|
||||
|
||||
Reference in New Issue
Block a user