1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Http\Controllers;
|
---|
4 |
|
---|
5 | use App\Models\Policeman;
|
---|
6 | use Illuminate\Contracts\Auth\Authenticatable;
|
---|
7 | use Illuminate\Http\Request;
|
---|
8 | use Illuminate\Support\Carbon;
|
---|
9 | use Illuminate\Support\Facades\DB;
|
---|
10 | use Illuminate\Support\Facades\Session;
|
---|
11 |
|
---|
12 | class OfficerController extends Controller
|
---|
13 | {
|
---|
14 | private function policeStationIsPoliceman()
|
---|
15 | {
|
---|
16 | return DB::table('police_station')
|
---|
17 | ->where('p_id', Session::get('p_id'))
|
---|
18 | ->get();
|
---|
19 | }
|
---|
20 | private function policeStationIsOfficer()
|
---|
21 | {
|
---|
22 | return DB::table('police_station')
|
---|
23 | ->where('pe_id', Session::get('pe_id'))
|
---|
24 | ->get();
|
---|
25 | }
|
---|
26 | function employees()
|
---|
27 | {
|
---|
28 | if(Session::get('pe_id') == null) {
|
---|
29 | return view('login');
|
---|
30 | }
|
---|
31 | if(Session::get('is_policeman')){
|
---|
32 | $police_station = $this->policeStationIsPoliceman();
|
---|
33 | } else {
|
---|
34 | $police_station = $this->policeStationIsOfficer();
|
---|
35 | }
|
---|
36 | $results = DB::table('policeman')
|
---|
37 | ->join('people', 'policeman.pe_id', '=', 'people.pe_id')
|
---|
38 | ->where('policeman.p_id', $police_station[0]->p_id)
|
---|
39 | ->get();
|
---|
40 |
|
---|
41 |
|
---|
42 | return view('employees', [
|
---|
43 | 'employees' => $results,
|
---|
44 | 'p_address'=>$police_station[0]->p_address
|
---|
45 | ]);
|
---|
46 | }
|
---|
47 |
|
---|
48 | function show($id){
|
---|
49 | if(Session::get('is_policeman')){
|
---|
50 | $police_station = $this->policeStationIsPoliceman();
|
---|
51 | } else {
|
---|
52 | $police_station = $this->policeStationIsOfficer();
|
---|
53 | }
|
---|
54 | $result = DB::table('policeman')
|
---|
55 | ->join('people', 'policeman.pe_id', '=', 'people.pe_id')
|
---|
56 | ->where('p_id', $police_station[0]->p_id)
|
---|
57 | ->where('people.pe_id', $id)
|
---|
58 | ->get();
|
---|
59 | $cases = DB::table('statements')
|
---|
60 | ->where('pe_id', $id)
|
---|
61 | ->get();
|
---|
62 | return view('employee', [
|
---|
63 | 'employee' => $result[0],
|
---|
64 | 'p_address'=>$police_station[0]->p_address,
|
---|
65 | 'cases' => $cases
|
---|
66 | ]);
|
---|
67 | }
|
---|
68 |
|
---|
69 | function register()
|
---|
70 | {
|
---|
71 | return view('register-policeman');
|
---|
72 | }
|
---|
73 | function register_post()
|
---|
74 | {
|
---|
75 | $policeman = request()->validate([
|
---|
76 | 'badge_no' => 'required',
|
---|
77 | 'embg' => 'required',
|
---|
78 | 'password' => 'required',
|
---|
79 | 'rank'=>'required'
|
---|
80 | ]);
|
---|
81 |
|
---|
82 |
|
---|
83 | $police_station = $this->policeStationIsOfficer();
|
---|
84 | $pe_id = DB::table('people')
|
---|
85 | ->where('embg', $policeman['embg'])->get();
|
---|
86 | $data = [
|
---|
87 | 'pe_id' => $pe_id[0]->pe_id,
|
---|
88 | 'badge_no' => $policeman["badge_no"],
|
---|
89 | 'p_date_of_employment' => Carbon::now()->format('Y-m-d'),
|
---|
90 | 'rank' => $policeman["rank"],
|
---|
91 | 'p_id' => $police_station[0]->p_id,
|
---|
92 | 'p_password' => $policeman["password"]
|
---|
93 | ];
|
---|
94 | DB::table('policeman')->insert($data);
|
---|
95 | // DB::insert('INSERT INTO policeman (pe_id, badge_no, p_date_of_employment, rank, p_id, p_password) VALUES (?, ?, ?, ?, ?, ?)', [$pe_id[0]->pe_id, $policeman["badge_no"], Carbon::now()->format('Y-m-d'), $policeman["rank"], $police_station[0]->p_id,$policeman["password"]]);
|
---|
96 | return redirect()->back()->with('message',"Додадено");
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | }
|
---|