Merged in izzati-feat-arcc-carian-nama (pull request #332)

tambah carian by nama
This commit is contained in:
izzati zulkifli
2025-08-04 00:27:02 +00:00
2 changed files with 43 additions and 2 deletions
+39 -2
View File
@@ -23,11 +23,27 @@ use DB;
class CustomerController extends Controller class CustomerController extends Controller
{ {
public function showAllCustomers(){ public function showAllCustomers(Request $request)
$customer = Customer::on('mysql7')->get(); {
$nama = $request->query('nama');
$kodcaw = $request->query('kodcaw');
$query = Customer::on('mysql7');
if ($nama) {
$query->where('nama', 'LIKE', '%' . $nama . '%');
}
if ($kodcaw) {
$query->where('kodcaw', $kodcaw);
}
$customer = $query->get();
return response()->json($customer); return response()->json($customer);
} }
public function getLatestCustomer($kodcaw){ public function getLatestCustomer($kodcaw){
$customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first(); $customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
@@ -962,4 +978,25 @@ class CustomerController extends Controller
return json_encode(['status'=> 'success']); return json_encode(['status'=> 'success']);
} }
public function searchByName(Request $request)
{
$nama = $request->query('nama');
$kodcaw = $request->query('kodcaw');
$query = Customer::query();
if ($kodcaw) {
$query->where('kodcaw', $kodcaw);
}
if ($nama) {
$query->where('nama', 'like', '%' . $nama . '%');
}
$results = $query->get();
return response()->json($results);
}
} }
+4
View File
@@ -60,6 +60,10 @@ $router->group(['prefix'=>'api'], function () use ($router){
$router->get('admin/customers/nokp/search',['uses'=>'CustomerController@showOneCustomerByICAdmin']); $router->get('admin/customers/nokp/search',['uses'=>'CustomerController@showOneCustomerByICAdmin']);
$router->get('customer/blacklist',['uses'=>'CustomerController@blacklistCustomer']); $router->get('customer/blacklist',['uses'=>'CustomerController@blacklistCustomer']);
$router->get('customer/eachcawangan/{ic}',['uses'=>'CustomerController@showCustomerByEachCawangan']); $router->get('customer/eachcawangan/{ic}',['uses'=>'CustomerController@showCustomerByEachCawangan']);
//arcc
$router->get('customer/searchbyname',['uses'=>'CustomerController@searchByName']);
// Route::get('/api/customers/searchbyname', [CustomerController::class, 'searchByName']);
//Change Password //Change Password
$router->post('changepassword/{kodcaw}/{id}',['uses'=>'CustomerController@changepassword']); $router->post('changepassword/{kodcaw}/{id}',['uses'=>'CustomerController@changepassword']);