|
|
@@ -3,8 +3,10 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Log;
|
|
|
+use App\Services\LogService;
|
|
|
use Exception;
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
|
+use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
@@ -20,16 +22,28 @@ class LogController extends Controller
|
|
|
* Display a listing of the resource.
|
|
|
*
|
|
|
* @param Request $request
|
|
|
- * @return Response
|
|
|
+ * @return LengthAwarePaginator
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
if (!Gate::allows('日志-查询')) {
|
|
|
return redirect(url('/'));
|
|
|
}
|
|
|
+ //没有查询条件,默认展示最近50条
|
|
|
+ if (!$request->has('created_at_start') &&
|
|
|
+ !$request->has('created_at_end') &&
|
|
|
+ !$request->has('operation') &&
|
|
|
+ !$request->has('type') &&
|
|
|
+ !$request->has('description')
|
|
|
+ ) {
|
|
|
+ $logs = Log::query()
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->paginate(50);
|
|
|
+ return view('maintenance.log.index', ['logs' => $logs]);
|
|
|
+ }
|
|
|
//不传开始时间提示错误信息并返回
|
|
|
- if(!$request->has('created_at_start')){
|
|
|
- session()->flash('warning','请选择开始时间');
|
|
|
+ if (!$request->has('created_at_start')) {
|
|
|
+ session()->flash('warning', '请选择开始时间');
|
|
|
return view('maintenance.log.index', ['logs' => null]);
|
|
|
}
|
|
|
$query = Log::query()
|
|
|
@@ -41,9 +55,9 @@ class LogController extends Controller
|
|
|
$query->where('type', 'like', $request->type . '%');
|
|
|
}
|
|
|
if ($request->has('description')) {
|
|
|
- $str=$request->description;
|
|
|
- $str = trim($str,'\\');
|
|
|
- $str = str_replace('\\','\\\\',$str);
|
|
|
+ $str = $request->description;
|
|
|
+ $str = trim($str, '\\');
|
|
|
+ $str = str_replace('\\', '\\\\', $str);
|
|
|
$query->where('description', 'like', '%' . $str . '%');
|
|
|
}
|
|
|
if ($request->has('created_at_start')) {
|
|
|
@@ -83,4 +97,10 @@ class LogController extends Controller
|
|
|
// $re=$log->delete();
|
|
|
// return ['success'=>$re];
|
|
|
}
|
|
|
+
|
|
|
+ public function syncRedisLogs()
|
|
|
+ {
|
|
|
+ LogService::syncRedisLogs();
|
|
|
+ return redirect('maintenance/log');
|
|
|
+ }
|
|
|
}
|