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