- Timestamp:
- 02/12/24 14:17:23 (11 months ago)
- Branches:
- main
- Children:
- 2bd3041
- Parents:
- 92df8cd
- Location:
- app/Http/Controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/OfficerController.php
r92df8cd r7e9dadd 17 17 return view('login'); 18 18 } 19 $results = DB::select('select * from policeman join people on policeman.pe_id = people.pe_id;'); 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 20 27 return view('employees', [ 21 'employees' => $results 28 'employees' => $results, 29 'p_address'=>$police_station[0]->p_address 22 30 ]); 23 31 } … … 36 44 ]); 37 45 46 47 $police_station = DB::select('select * from police_station where pe_id=:pe_id;',['pe_id'=> Session::get('pe_id')]); 48 38 49 $pe_id = DB::select('select pe_id from people where embg = :embg;', ['embg' => $policeman["embg"]]); 39 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,$policeman["password"]]);40 return view('register-policeman');50 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"]]); 51 return redirect()->back()->with('message',"Додадено"); 41 52 } 42 53 -
app/Http/Controllers/PeopleController.php
r92df8cd r7e9dadd 23 23 return view('login'); 24 24 } 25 // $credentials = request()->validate([ 26 // 'embg' => 'required' 27 // ]); 28 // $embg = $credentials['embg']; 29 // 30 // $peoples = DB::select('SELECT * FROM people WHERE embg ~ :embg', ['embg' => '^' . $embg]); 31 25 32 $credentials = request()->validate([ 26 'embg' => 'required' 33 'embg' => 'nullable', // Assuming embg is not always required 34 'gender' => 'nullable', 35 'age' => 'nullable', 27 36 ]); 28 $ embg = $credentials['embg'];37 $query = 'SELECT * FROM people WHERE true'; 29 38 30 $peoples = DB::select('SELECT * FROM people WHERE embg ~ :embg', ['embg' => '^' . $embg]); 39 $embg = '^' . $credentials['embg']; 40 if ($credentials['embg']) { 41 $query .= " AND embg LIKE '{$credentials['embg']}%'"; 42 } 31 43 32 return view('filter', [ 33 'peoples' => $peoples 34 ]); 44 // Check if $credentials['gender'] is an array and handle accordingly 45 if (isset($credentials['gender']) && (is_array($credentials['gender']) && count($credentials['gender']) > 0)) { 46 $genderConditions = implode(" OR ", array_map(function ($gender) { 47 return "gender = '{$gender}'"; 48 }, $credentials['gender'])); 49 50 $query .= " AND ({$genderConditions})"; 51 } elseif (isset($credentials['gender']) && !is_array($credentials['gender'])) { 52 $query .= " AND gender = '{$credentials['gender']}'"; 53 } 54 55 // Check if $credentials['age'] is an array and handle accordingly 56 if (isset($credentials['age']) && is_array($credentials['age']) && count($credentials['age']) > 0) { 57 $ageConditions = []; 58 59 foreach ($credentials['age'] as $ageRange) { 60 // Extract minimum and maximum ages from the range 61 list($minAge, $maxAge) = explode('-', $ageRange); 62 63 // Add condition for the age range 64 $ageConditions[] = "EXTRACT(YEAR FROM AGE(current_date, date_of_birth)) BETWEEN {$minAge} AND {$maxAge}"; 65 } 66 67 $query .= " AND (" . implode(" OR ", $ageConditions) . ")"; 68 } 69 // Use a raw SQL query with the built conditions 70 71 $peoples = DB::select($query); 72 return view('filter', ['peoples' => $peoples]); 35 73 } 36 74 public function getPerson(Request $request) -
app/Http/Controllers/SessionsController.php
r92df8cd r7e9dadd 46 46 Session::put('pe_id', $exists[0]->pe_id); 47 47 } 48 return redirect()->intended('/');48 return view('welcome'); 49 49 } 50 50
Note:
See TracChangeset
for help on using the changeset viewer.