All pages updated with all features including filters
This commit is contained in:
@@ -105,7 +105,7 @@ class BooksPublishedController extends Controller
|
||||
return response()->json(['success' => 'Publication deleted successfully']);
|
||||
}
|
||||
|
||||
public function getBooksPublishedResponses()
|
||||
public function getBooksPublishedResponses(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$isAdmin = $user->role->name === 'Admin';
|
||||
@@ -127,6 +127,21 @@ class BooksPublishedController extends Controller
|
||||
->where('faculty_id', $user->id);
|
||||
}
|
||||
|
||||
// Apply filters
|
||||
if ($request->has('department_id') && !empty($request->department_id)) {
|
||||
$booksPublisheds->whereHas('department', function ($query) use ($request) {
|
||||
$query->where('id', $request->department_id);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('publisher') && !empty($request->publisher)) {
|
||||
$booksPublisheds->where('publisher', $request->publisher);
|
||||
}
|
||||
|
||||
if ($request->has('date_of_publication') && !empty($request->date_of_publication)) {
|
||||
$booksPublisheds->where('date_of_publication', $request->date_of_publication);
|
||||
}
|
||||
|
||||
return DataTables::of($booksPublisheds)
|
||||
->addColumn('user_name', function ($booksPublished) {
|
||||
return $booksPublished->user->name ?? 'Unknown';
|
||||
@@ -149,14 +164,26 @@ class BooksPublishedController extends Controller
|
||||
->addColumn('date_of_publication', function ($booksPublished) {
|
||||
return \Carbon\Carbon::parse($booksPublished->date_of_publication)->format('d-m-Y');
|
||||
})
|
||||
->filterColumn('user_name', function($query, $keyword) {
|
||||
$query->whereHas('user', fn($q) => $q->where('name', 'like', "%{$keyword}%"));
|
||||
})
|
||||
->filterColumn('author', fn($query, $keyword) =>
|
||||
$query->where('author', 'like', "%{$keyword}%")
|
||||
)
|
||||
->filterColumn('title', fn($query, $keyword) =>
|
||||
$query->where('title', 'like', "%{$keyword}%")
|
||||
)
|
||||
->filterColumn('issn', fn($query, $keyword) =>
|
||||
$query->where('issn', 'like', "%{$keyword}%")
|
||||
)
|
||||
->addColumn('action', function ($booksPublished) {
|
||||
$actions = [];
|
||||
|
||||
// View proof button for everyone
|
||||
if ($booksPublished->proof) {
|
||||
$actions[] = '<a href="' . asset('storage/' . $booksPublished->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1">View</a>';
|
||||
$actions[] = '<a href="' . asset('storage/' . $booksPublished->proof) . '" target="_blank" class="btn btn-sm btn-primary mr-1"><i class="fas fa-eye"></i></a>';
|
||||
} else {
|
||||
$actions[] = 'No Proof';
|
||||
$actions[] = '<span class="text-muted"><i class="fas fa-times-circle"></i></span>';
|
||||
}
|
||||
|
||||
// Edit button with role-appropriate route
|
||||
@@ -170,10 +197,10 @@ class BooksPublishedController extends Controller
|
||||
$editRoute = route('faculty.BooksPublished.edit', $booksPublished->id);
|
||||
}
|
||||
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1">Edit</a>';
|
||||
$actions[] = '<a href="' . $editRoute . '" class="btn btn-sm btn-info mx-1"><i class="fas fa-edit"></i></a>';
|
||||
|
||||
$deleteRoute = route('booksPublished.destroy', $booksPublished->id);
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $booksPublished->id . '" data-url="' . $deleteRoute . '">Delete</button>';
|
||||
$actions[] = '<button type="button" class="btn btn-sm btn-danger delete-btn" data-id="' . $booksPublished->id . '" data-url="' . $deleteRoute . '"><i class="fas fa-trash"></i></button>';
|
||||
|
||||
return implode(' ', $actions);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user