I’ve been assigned at work with doing some stuff to an already existing webpage, and one of them is implementing more searchbars based on one already there. I have copied almost everything, but for some reason, I end up with error 404 once I try to make said search.
I’ll post now all snippets of code related to the search I’m creating (searchActByEntity) and the one I’m taking as reference (searchActByDate):
web.php
Route::get("searchActByDate", [ActivityController::class, 'searchActByDate']);
Route::get("searchActByEntity", [ActivityController::class, 'searchActByEntity']);
ActivityController.php
public function searchActByDate(Request $request){
if($request->ajax()) {
$query = $request->get('searchActivity');
$activityTypes = TypeActivity::all();
if(empty($query)) {
$activities=Activity::orderBy('dateAct', 'desc')
->whereDate('dateAct', '<', date('Y-m-d'))
->get();
} else {
$activities=Activity::orderBy('dateAct', 'desc')
->whereDate('dateAct', '<', date('Y-m-d'))
->where('dateAct', 'like', '%'.$request->searchActivity.'%')
->orwhere('nameAct','like','%'.$request->searchActivity.'%')
->get();
}
$total = $activities->count();
$html = view('dashboard.partials.itemListActivity', [
'activities' => $activities,
'activityTypes' => $activityTypes,
])->render();
return response()->json([
'success' => true,
'html' => $html,
'total' => $total,
], 200);
}else{
return response()->json([
'success' => false,
'message' => "Something went wrong!",
], 403);
}
}
public function searchActByEntity(Request $request) {
if($request->ajax()) {
$query = $request->get('searchEntity');
$activityTypes = TypeActivity::all();
if(empty($query)) {
$activities=Activity::orderBy('dateAct', 'desc')
->get();
} else {
$activities=Activity::orderBy('dateAct', 'desc')
->where('entityAct', 'like', '%'.$request->searchEntity.'%')
->get();
}
$total = $activities->count();
$html = view('dashboard.partials.itemListActivity', [
'activities' => $activities,
'activityTypes' => $activityTypes,
])->render();
return response()->json([
'success' => true,
'html' => $html,
'total' => $total,
], 200);
}else{
return response()->json([
'success' => false,
'message' => "Something went wrong!",
], 403);
}
}
showAllActivities.blade.php (where the code executes), inside document.ready
function ajaxAntiguas(datos){
return $.ajax({
url:"searchActByDate",
type:"GET",
data:{'searchActivity':datos},
success:function(data){
$('#search_listAct').html(data.html);
}
})
}
function ajaxEntity(datos) {
return $.ajax({
url: "searchActByEntity",
type: "GET",
data:{'searchEntity':datos},
success:function(data){
$('#search_listAct').html(data.html);
}
})
}
$("#searchEntity").on('keyup', function() {
var query = $(this).val();
ajaxEntity(query);
});
$('#searchActivity').on('keyup', function(){
var query = $(this).val();
if($('#button-past-act').hasClass('seleccionado')){
ajaxAntiguas(query);
}else if($('#button-nulled-act').hasClass('seleccionado')){
ajaxNulas(query);
}else if($('#button-avaliable-act').hasClass('seleccionado')){
ajaxDisponibles(query);
} else {
ajaxCall(query);
}
});
As you can see, the other is part of a bigger thing, but I don’t think that’s part of the issue. Anything else you need to see, let me know, cause I’m stumped. Thanks in advance!