fix search like in quick search and pbg data
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Http\Resources\TaskAssignmentsResource;
|
||||
use App\Models\PbgTask;
|
||||
use App\Models\TaskAssignment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class QuickSearchController extends Controller
|
||||
{
|
||||
@@ -24,18 +25,24 @@ class QuickSearchController extends Controller
|
||||
public function quick_search_datatable(Request $request)
|
||||
{
|
||||
try {
|
||||
$query = PbgTask::orderBy('id', 'desc');
|
||||
$query = PbgTask::leftJoin('pbg_task_details', 'pbg_task.uuid', '=', 'pbg_task_details.pbg_task_uid')
|
||||
->select('pbg_task.*')
|
||||
->orderBy('pbg_task.id', 'desc');
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->get('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('registration_number', 'LIKE', "%$search%");
|
||||
$q->where('pbg_task.registration_number', 'LIKE', "%$search%")
|
||||
->orWhere('pbg_task.name', 'LIKE', "%$search%")
|
||||
->orWhere('pbg_task.owner_name', 'LIKE', "%$search%")
|
||||
->orWhere('pbg_task.address', 'LIKE', "%$search%")
|
||||
->orWhere('pbg_task_details.name_building', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json($query->paginate());
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error("Error fetching datatable data: " . $e->getMessage());
|
||||
Log::error("Error fetching datatable data: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'message' => 'Terjadi kesalahan saat mengambil data.',
|
||||
'error' => $e->getMessage(),
|
||||
@@ -57,10 +64,10 @@ class QuickSearchController extends Controller
|
||||
|
||||
return view("quick-search.detail", compact("data", 'statusOptions', 'applicationTypes'));
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
\Log::warning("PbgTask with ID {$id} not found.");
|
||||
Log::warning("PbgTask with ID {$id} not found.");
|
||||
return redirect()->route('quick-search.index')->with('error', 'Data tidak ditemukan.');
|
||||
} catch (\Throwable $e) {
|
||||
\Log::error("Error in QuickSearchController@show: " . $e->getMessage());
|
||||
Log::error("Error in QuickSearchController@show: " . $e->getMessage());
|
||||
return response()->view('pages.404', [], 500); // Optional: create `resources/views/errors/500.blade.php`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user