47 lines
1.7 KiB
PHP
47 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$nickname = $request->nickname;
|
|
$start = $request->start;
|
|
$end = $request->end;
|
|
$orderField = $request->orderField;
|
|
$orderDirection = $request->orderDirection;
|
|
$numPerPage = $request->numPerPage ?: 30;
|
|
|
|
$notifications = DatabaseNotification::when($start && $end, function ($query) use ($start,$end) {
|
|
return $query->whereBetween('created_at', [$start, date('Y-m-d', strtotime("+1 days", strtotime($end)))]);
|
|
})->when($start && !$end, function ($query) use ($start) {
|
|
return $query->where('created_at', '>=', $start);
|
|
})->when(!$start && $end, function ($query) use ($end) {
|
|
return $query->where('created_at', '<=', date('Y-m-d', strtotime("+1 days", strtotime($end))));
|
|
})->when($orderField, function ($query) use ($orderField, $orderDirection) {
|
|
$query->orderBy($orderField, $orderDirection);
|
|
})->orderBy('created_at', 'desc')->paginate($numPerPage);
|
|
return view('Admin::notifications.index', compact('notifications'));
|
|
}
|
|
|
|
public function destroy(Request $request, $notification)
|
|
{
|
|
if ($notification == 'batch') {
|
|
$result = DatabaseNotification::whereIn('id', $request->ids)->delete();
|
|
} else {
|
|
$result = DatabaseNotification::where('id', $notification)->delete();
|
|
}
|
|
|
|
if ($result) {
|
|
return $this->success();
|
|
} else {
|
|
return $this->error();
|
|
}
|
|
}
|
|
}
|