Skip to content

Instantly share code, notes, and snippets.

@nafiesl
Last active July 20, 2017 10:19
Show Gist options
  • Save nafiesl/d0afdb062b171ec1c1509aa9c9588dbe to your computer and use it in GitHub Desktop.
Save nafiesl/d0afdb062b171ec1c1509aa9c9588dbe to your computer and use it in GitHub Desktop.
Laravel Log Viewer
<?php
// app/Http/Controllers/LogFilesController.php
namespace App\Http\Controllers;
class LogFilesController extends Controller
{
public function index()
{
if (!file_exists(storage_path('logs'))) {
return [];
}
$logFiles = \File::allFiles(storage_path('logs'));
// Sort files by modified time DESC
usort($logFiles, function ($a, $b) {
return -1 * strcmp($a->getMTime(), $b->getMTime());
});
return view('log-files', compact('logFiles'));
}
}
@extends('layouts.app')
@section('title','Log Files')
@section('content')
<h3 class="page-header">Application Log Files</h3>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<table class="table table-condensed">
<thead>
<th>#</th>
<th>File Name</th>
<th>Size</th>
<th>Time</th>
<th>{{ trans('app.action') }}</th>
</thead>
<tbody>
@forelse($logFiles as $key => $logFile)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $logFile->getFilename() }}</td>
<td>{{ $logFile->getSize() }}</td>
<td>{{ date('Y-m-d H:i:s', $logFile->getMTime()) }}</td>
<td>
<a href="{{ route('log-files.show', $logFile->getFilename()) }}" title="Show file {{ $logFile->getFilename() }}">View</a> |
<a href="{{ route('log-files.download', $logFile->getFilename()) }}" title="Download file {{ $logFile->getFilename() }}">Download</a>
</td>
</tr>
@empty
<tr>
<td colspan="3">No Log File Exists</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
@endsection
<?php
// routes/web.php
Route::get('log-files', ['as' => 'log-files.index', 'uses' => 'LogFilesController@index']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment