diff --git a/composer.json b/composer.json index 45b6c13..0caebaf 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tripteki/laravelphp-log", - "version": "1.0.1", + "version": "1.1.0", "description": "Trip Teknologi's Laravel.php Logs", "readme": "README.md", diff --git a/stubs/app/Exports/Logs/.gitkeep b/stubs/app/Exports/Logs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/stubs/app/Exports/Logs/LogExport.php b/stubs/app/Exports/Logs/LogExport.php new file mode 100644 index 0000000..7e7ef86 --- /dev/null +++ b/stubs/app/Exports/Logs/LogExport.php @@ -0,0 +1,64 @@ + [ "font" => [ "bold" => true, ], ], + ]; + } + + /** + * @return array + */ + public function headings(): array + { + return [ + + "ID", + "Causer Type", + "Causer ID", + "Subject Type", + "Subject ID", + "Log Name", + "Properties", + "Event", + "Created At", + "Updated At", + ]; + } + + /** + * @return \Illuminate\Database\Eloquent\Collection + */ + public function collection() + { + return \Spatie\Activitylog\ActivitylogServiceProvider::getActivityModelInstance()->all([ + + "id", + "causer_type", + "causer_id", + "subject_type", + "subject_id", + "log_name", + "properties", + "event", + "created_at", + "updated_at", + ]); + } +}; diff --git a/stubs/app/Http/Controllers/Admin/Log/LogAdminController.php b/stubs/app/Http/Controllers/Admin/Log/LogAdminController.php index 0eb3bbf..caa22bc 100644 --- a/stubs/app/Http/Controllers/Admin/Log/LogAdminController.php +++ b/stubs/app/Http/Controllers/Admin/Log/LogAdminController.php @@ -5,8 +5,11 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; +use Maatwebsite\Excel\Facades\Excel; use Tripteki\Log\Contracts\Repository\Admin\ILogRepository; +use App\Exports\Log\LogExport; use App\Http\Requests\Admin\Logs\LogShowValidation; +use Tripteki\Helpers\Http\Requests\FileExportValidation; use Tripteki\Helpers\Http\Controllers\Controller; class LogAdminController extends Controller @@ -108,4 +111,51 @@ public function show(LogShowValidation $request, $log) return iresponse($data, $statecode); } + + /** + * @OA\Get( + * path="/admin/logs-export", + * tags={"Admin Log"}, + * summary="Export", + * @OA\Parameter( + * required=false, + * in="query", + * name="file", + * schema={"type": "string", "enum": {"csv", "xls", "xlsx"}}, + * description="Log's File." + * ), + * @OA\Response( + * response=200, + * description="Success." + * ), + * @OA\Response( + * response=422, + * description="Unprocessable Entity." + * ) + * ) + * + * @param \Tripteki\Helpers\Http\Requests\FileExportValidation $request + * @return mixed + */ + public function export(FileExportValidation $request) + { + $form = $request->validated(); + $data = []; + $statecode = 200; + + if ($form["file"] == "csv") { + + $data = Excel::download(new LogExport(), "Log.csv", \Maatwebsite\Excel\Excel::CSV); + + } else if ($form["file"] == "xls") { + + $data = Excel::download(new LogExport(), "Log.xls", \Maatwebsite\Excel\Excel::XLS); + + } else if ($form["file"] == "xlsx") { + + $data = Excel::download(new LogExport(), "Log.xlsx", \Maatwebsite\Excel\Excel::XLSX); + } + + return $data; + } }; diff --git a/stubs/routes/admin/log.php b/stubs/routes/admin/log.php index c81c42d..ff005d7 100644 --- a/stubs/routes/admin/log.php +++ b/stubs/routes/admin/log.php @@ -9,4 +9,5 @@ * Logs. */ Route::apiResource("logs", LogAdminController::class)->only([ "index", "show", ])->parameters([ "logs" => "log", ]); + Route::get("logs-export", [ LogAdminController::class, "export", ]); });