# PageController
app / Http / Controllers / PageController.php
# index
public function index(){
return view('index');
}
1
2
3
2
3
# qrScanStore
public function qrScanStore(Request $request){
$today = now()->format('D');
if ($today == "Sat" || $today == "Sun"){
return[
'status' => 'Fail',
'message' => 'Today is weekend.'
];
}
if (!Hash::check(date('Y-m-d'), $request->hash_value)){
return [
'status' => 'Fail',
'message' => 'QR Code Is Invalid.'
];
}
$employee = Auth::user();
// same with checkincheckout
$datas = CheckInCheckOut::firstOrCreate(
[
'user_id' => $employee->id,
'Indate' => now()->format('Y-m-d')
]
);
if (!is_null($datas->checkIn_time) && !is_null($datas->checkOut_time)){
return[
'status' => 'Fail',
'message' => 'You have done Check In and Check Out at today.',
];
}
if (is_null($datas->checkIn_time)){
$datas->checkIn_time = now();
$message = 'Successfully Check In At '.now();
}else{
if (is_null($datas->checkOut_time)){
$datas->checkOut_time = now();
$message = 'Successfully Check Out At '.now();
}
}
$datas->update();
return[
'status' => 'Success',
'message' => $message,
];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Code Overview
<?php
namespace App\Http\Controllers;
use App\Models\CheckInCheckOut;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class PageController extends Controller
{
public function index(){
return view('index');
}
public function userScan(){
return view('Attendance.user');
}
public function qrScanStore(Request $request){
$today = now()->format('D');
if ($today == "Sat" || $today == "Sun"){
return[
'status' => 'Fail',
'message' => 'Today is weekend.'
];
}
if (!Hash::check(date('Y-m-d'), $request->hash_value)){
return [
'status' => 'Fail',
'message' => 'QR Code Is Invalid.'
];
}
$employee = Auth::user();
// same with checkincheckout
$datas = CheckInCheckOut::firstOrCreate(
[
'user_id' => $employee->id,
'Indate' => now()->format('Y-m-d')
]
);
if (!is_null($datas->checkIn_time) && !is_null($datas->checkOut_time)){
return[
'status' => 'Fail',
'message' => 'You have done Check In and Check Out at today.',
];
}
if (is_null($datas->checkIn_time)){
$datas->checkIn_time = now();
$message = 'Successfully Check In At '.now();
}else{
if (is_null($datas->checkOut_time)){
$datas->checkOut_time = now();
$message = 'Successfully Check Out At '.now();
}
}
$datas->update();
return[
'status' => 'Success',
'message' => $message,
];
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66