diff --git a/routes/api.php b/routes/api.php index 201b0ae..c5c8cc5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,5 @@ input('file', 'laravel.log')); + public function index() + { + Ward::setFile($file = request()->input('file', 'laravel.log')); - $logs = Ward::all(); + $logs = Ward::all(); - $currentPage = LengthAwarePaginator::resolveCurrentPage(); + $currentPage = LengthAwarePaginator::resolveCurrentPage(); - $collection = collect($logs); + $collection = collect($logs); - $search = request()->input('search'); + $search = request()->input('search'); - if ($search) - $collection = $collection->filter(function ($log) use ($search) { - return false !== stristr($log['text'], $search); - }); + if ($search) { + $collection = $collection->filter(function ($log) use ($search) { + return false !== stristr($log['text'], $search); + }); + } - $perPage = 6; + $perPage = 6; - $currentPageSearchResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->values()->toArray(); + $currentPageSearchResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->values()->toArray(); - return new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); - } + return new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); + } - public function dailyLogFiles() - { - return collect(Ward::getFiles(true))->filter(function ($file) { - return strpos($file, 'laravel') === 0; - }); - } + public function dailyLogFiles() + { + return collect(Ward::getFiles(true))->filter(function ($file) { + return strpos($file, 'laravel') === 0; + }); + } } diff --git a/src/Http/Middleware/Authorize.php b/src/Http/Middleware/Authorize.php index 148e2b8..2173db3 100644 --- a/src/Http/Middleware/Authorize.php +++ b/src/Http/Middleware/Authorize.php @@ -15,4 +15,4 @@ public function handle(Request $request, Closure $next): Response ? $next($request) : abort(403); } -} \ No newline at end of file +} diff --git a/tests/ToolControllerTest.php b/tests/ToolControllerTest.php index 1f8aee2..46f8bfc 100644 --- a/tests/ToolControllerTest.php +++ b/tests/ToolControllerTest.php @@ -2,10 +2,6 @@ namespace KABBOUCHI\LogsTool\Tests; -use KABBOUCHI\LogsTool\Http\Controllers\LogsController; -use KABBOUCHI\LogsTool\LogsTool; -use Symfony\Component\HttpFoundation\Response; - class ToolControllerTest extends TestCase { /** @test */