tambah carian by nama
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user