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 | function employees()
|
---|
15 | {
|
---|
16 | if(Session::get('pe_id') == null) {
|
---|
17 | return view('login');
|
---|
18 | }
|
---|
19 | if(Session::get('is_policeman')){
|
---|
20 | $police_station = DB::select('select * from police_station where p_id=:p_id;',['p_id'=> Session::get('p_id')]);
|
---|
21 | } else {
|
---|
22 | $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=> Session::get('pe_id')]);
|
---|
23 | }
|
---|
24 | $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id where p_id=:p_id;',['p_id'=> $police_station[0]->p_id]);
|
---|
25 | // $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id;');
|
---|
26 |
|
---|
27 | return view('employees', [
|
---|
28 | 'employees' => $results,
|
---|
29 | 'p_address'=>$police_station[0]->p_address
|
---|
30 | ]);
|
---|
31 | }
|
---|
32 |
|
---|
33 | function show($id){
|
---|
34 | if(Session::get('is_policeman')){
|
---|
35 | $police_station = DB::select('select * from police_station where p_id=:p_id;',['p_id'=> Session::get('p_id')]);
|
---|
36 | } else {
|
---|
37 | $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=> Session::get('pe_id')]);
|
---|
38 | }
|
---|
39 | $result = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id where p_id=:p_id and people.pe_id=:pe_id;',['p_id'=> $police_station[0]->p_id, 'pe_id' => $id]);
|
---|
40 | $cases = DB::select('select * from statements where pe_id=:pe_id;',['pe_id' => $id]);
|
---|
41 |
|
---|
42 | return view('employee', [
|
---|
43 | 'employee' => $result[0],
|
---|
44 | 'p_address'=>$police_station[0]->p_address,
|
---|
45 | 'cases' => $cases
|
---|
46 | ]);
|
---|
47 | }
|
---|
48 |
|
---|
49 | function register()
|
---|
50 | {
|
---|
51 | return view('register-policeman');
|
---|
52 | }
|
---|
53 | function register_post()
|
---|
54 | {
|
---|
55 | $policeman = request()->validate([
|
---|
56 | 'badge_no' => 'required',
|
---|
57 | 'embg' => 'required',
|
---|
58 | 'password' => 'required',
|
---|
59 | 'rank'=>'required'
|
---|
60 | ]);
|
---|
61 |
|
---|
62 |
|
---|
63 | $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=> Session::get('pe_id')]);
|
---|
64 |
|
---|
65 | $pe_id = DB::select('select pe_id from people where embg = :embg;', ['embg' => $policeman["embg"]]);
|
---|
66 | 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"]]);
|
---|
67 | return redirect()->back()->with('message',"Додадено");
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | }
|
---|