tambah carian by nama

This commit is contained in:
Nur Izzati
2025-08-03 12:33:43 +08:00
parent 63a3f4870a
commit a3234a925c
2 changed files with 43 additions and 2 deletions
+39 -2
View File
@@ -23,11 +23,27 @@ use DB;
class CustomerController extends Controller
{
public function showAllCustomers(){
$customer = Customer::on('mysql7')->get();
public function showAllCustomers(Request $request)
{
$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);
}
public function getLatestCustomer($kodcaw){
$customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
@@ -962,4 +978,25 @@ class CustomerController extends Controller
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('customer/blacklist',['uses'=>'CustomerController@blacklistCustomer']);
$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
$router->post('changepassword/{kodcaw}/{id}',['uses'=>'CustomerController@changepassword']);