Probably a difference in timezones for local versus the server.
Php laravel don't work the same as in local when deployed to shared hosting, cPanel
So, currently, my web-app is working correctly in local. The problem in shared hosting is that when I clock out, it automatically changes all the time clock-out and location clock-out of all the other users as well. Here is the screenshot in local, https://paste.pics/48b6310c2e1bdf728ccedc9ed6fd42ce and here is the screenshot when deployed to shared hosting(cPanel), it is behaving like this, https://paste.pics/f0a9c1aafc62e5edbb0157bf8c1de1e6 .
I've tried reuploading everything for third times, double checking on the controller file in shared hosting, api.php in routes, and the blade.php file in views, resetting all the data and restarting again and it's still the same in shared hosting. I wonder what's wrong ? Please help, I've stucked at this bug since last week friday.
Below are the code taken from hosting using WinSCP
Api.php in routes
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserProfileController;
Route::post('login', [AuthController::class, 'login']);
Route::get('getdata', [UserProfileController::class, 'getdata']);
Route::post('getdata/{id}', [UserProfileController::class, 'showdata']);
Route::post('adduser', [UserProfileController::class, 'adddata']);
Route::delete('deleteuser', [UserProfileController::class, 'deleteuser']);
Route::PUT('updateuser', [UserProfileController::class, 'updateuser']);
Route::post('updateuserClockIn', [UserProfileController::class, 'userClockIn']);
Route::post('updateuserClockOut', [UserProfileController::class, 'userClockOut']);
Route::middleware('auth:sanctum')->get('user', function (Request $request) {
return $request->user();
});
function in UserProfileController,
public function userClockIn(Request $r)
{
$result = [];
$result['status'] = false;
$result['message'] = "something error";
$users = User::where('staff_id', $r->staff_id)->select(['staff_id', 'date_checkIn', 'time_checkIn', 'location_checkIn'])->first();
$mytime = Carbon::now('Asia/Kuala_Lumpur');
$date = $mytime->format('Y-m-d');
$time = $mytime->format('H:i:s');
$users->date_checkIn = $date;
$users->time_checkIn = $time;
$users->location_checkIn = $r->location_checkIn;
AttendanceRecord::updateOrCreate(
['staff_id' => $users->staff_id, 'date_checkIn' => $date],
$users->toArray()
);
$result['data'] = $users;
$result['status'] = true;
$result['message'] = "suksess add data";
return response()->json($result);
}
public function userClockOut(Request $r)
{
$result = [];
$result['status'] = false;
$result['message'] = "something error";
$users = User::where('staff_id', $r->staff_id)->select(['staff_id', 'time_checkOut', 'location_checkOut'])->first();
$mytime = Carbon::now('Asia/Kuala_Lumpur');
$date = $mytime->format('Y-m-d');
$time = $mytime->format('H:i:s');
$users->date_checkIn = $date;
$users->time_checkOut = $time;
$users->location_checkOut = $r->location_checkOut;
// Save the updated data to the database
AttendanceRecord::updateOrCreate(
['staff_id' => $users->staff_id, 'date_checkIn' => $date],
$users->toArray()
);
$result['data'] = $users;
$result['status'] = true;
$result['message'] = "suksess add data";
return response()->json($result);
}
blade.php files in views displaying the History page,
<tbody class="bg-white divide-y divide-gray-200">
@php
$no = 1
@endphp
@foreach ($history as $row)
<tr>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900"> {{ $no++ }} </div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900"> {{ $row->staff_id }} </div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900"> {{ $row->date_checkIn }} </div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900"> {{ $row->time_checkIn }} </div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $row->location_checkIn }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $row->time_checkOut }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $row->location_checkOut }}
</td>
</tr>
@endforeach
</tbody>
Please or to participate in this conversation.